Skip to content

Commit

Permalink
Rework messaging
Browse files Browse the repository at this point in the history
- Following nanoframework#2082.
  • Loading branch information
josesimoes committed Sep 29, 2021
1 parent f973f81 commit 53043f5
Showing 1 changed file with 7 additions and 18 deletions.
25 changes: 7 additions & 18 deletions src/CLR/Messaging/Messaging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include <WireProtocol.h>
#include <WireProtocol_Message.h>

CLR_Messaging *g_CLR_Messaging;
CLR_Messaging g_CLR_Messaging;

////////////////////////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -92,7 +92,7 @@ bool CLR_Messaging::Messaging_Query__Reply(WP_Message *msg)
CLR_Messaging_Commands::Messaging_Query::Reply *cmd =
(CLR_Messaging_Commands::Messaging_Query::Reply *)msg->m_payload;

g_CLR_Messaging->AllocateAndQueueMessage(
g_CLR_Messaging.AllocateAndQueueMessage(
CLR_Messaging_Commands::c_Messaging_Query,
0,
NULL,
Expand All @@ -115,7 +115,7 @@ bool CLR_Messaging::Messaging_Send(WP_Message *msg)

len = msg->m_header.m_size - sizeof(cmd->m_addr);

fRes = g_CLR_Messaging->AllocateAndQueueMessage(
fRes = g_CLR_Messaging.AllocateAndQueueMessage(
CLR_Messaging_Commands::c_Messaging_Send,
len,
cmd->m_data,
Expand Down Expand Up @@ -154,7 +154,7 @@ bool CLR_Messaging::Messaging_Reply(WP_Message *msg)
CLR_UINT32 len;

len = msg->m_header.m_size - sizeof(cmd->m_addr);
fRes = g_CLR_Messaging->AllocateAndQueueMessage(
fRes = g_CLR_Messaging.AllocateAndQueueMessage(
CLR_Messaging_Commands::c_Messaging_Reply,
len,
cmd->m_data,
Expand Down Expand Up @@ -254,17 +254,11 @@ HRESULT CLR_Messaging::CreateInstance()
NATIVE_PROFILE_CLR_MESSAGING();
NANOCLR_HEADER();

// allocate memory for messenger instance
g_CLR_Messaging = (CLR_Messaging *)platform_malloc(sizeof(CLR_Messaging));

// sanity check...
FAULT_ON_NULL(g_CLR_Messaging);

NANOCLR_CLEAR(g_CLR_Messaging);

g_CLR_Messaging->Initialize(NULL, 0, NULL, 0);
g_CLR_Messaging.Initialize(NULL, 0, NULL, 0);

NANOCLR_NOCLEANUP();
NANOCLR_NOCLEANUP_NOLABEL();
}

//--//
Expand Down Expand Up @@ -302,12 +296,7 @@ HRESULT CLR_Messaging::DeleteInstance()
NATIVE_PROFILE_CLR_MESSAGING();
NANOCLR_HEADER();

g_CLR_Messaging->Cleanup();

// free messenger instance
platform_free(g_CLR_Messaging);

g_CLR_Messaging = NULL;
g_CLR_Messaging.Cleanup();

NANOCLR_NOCLEANUP_NOLABEL();
}
Expand Down

0 comments on commit 53043f5

Please sign in to comment.