Skip to content

Commit

Permalink
One NodeShared per process (gazebosim#137)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Oxoby <[email protected]>
  • Loading branch information
Juan Oxoby committed May 15, 2020
1 parent 012bba6 commit 485b5ff
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/NodeShared.cc
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ void sendAuthErrorHelper(zmq::socket_t &_socket, const std::string &_err)
//////////////////////////////////////////////////
NodeShared *NodeShared::Instance()
{
#ifdef _MSC_VER
// If we compile ign-transport as a shared library on Windows, we should
// never destruct NodeShared, unfortunately. It seems that WinSock does
// not behave well during the DLL teardown phase as a program exits, and
Expand All @@ -139,12 +138,17 @@ NodeShared *NodeShared::Instance()
// application exits. We may want to consider a more elegant solution in
// the future. The zsys_shutdown() function in the czmq library may be able
// to provide some inspiration for solving this more cleanly.
static NodeShared *instance = new NodeShared();

static NodeShared *instance = nullptr;

// Create a new singleton of NodeShared if the the process has changed
// (maybe after fork?) so the ZMQ context is not shared between them.
if (instance == nullptr || instance->pUuid != Uuid().ToString())
{
instance = new NodeShared();
}

return instance;
#else
static NodeShared instance;
return &instance;
#endif
}

//////////////////////////////////////////////////
Expand Down

0 comments on commit 485b5ff

Please sign in to comment.