Skip to content

Commit

Permalink
rework
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenhauer committed Oct 10, 2023
1 parent c8be7e5 commit f1cfc89
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
24 changes: 15 additions & 9 deletions source/adios2/toolkit/remote/Remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,22 @@ void ReadResponseHandler(CManager cm, CMConnection conn, void *vevent, void *cli
return;
};

CManagerSingleton &CManagerSingleton::Instance(RemoteCommon::Remote_evpath_state &ev_state)
{
static CManagerSingleton self = [&ev_state] {
CManagerSingleton instance;
ev_state = instance.internalEvState;
return instance;
}();
ev_state = self.internalEvState;
return self;
}

void Remote::InitCMData()
{
std::lock_guard<std::mutex> lockGuard(m_CMInitMutex);
bool first = true;
auto CM = CManagerSingleton::Instance(first);
ev_state.cm = CM->m_cm;
RegisterFormats(ev_state);
if (first)
{
CMfork_comm_thread(ev_state.cm);
(void)CManagerSingleton::Instance(ev_state);
static std::once_flag flag;
std::call_once(flag, [&]() {
CMregister_handler(ev_state.OpenResponseFormat, (CMHandlerFunc)OpenResponseHandler,
&ev_state);
CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler,
Expand All @@ -68,7 +74,7 @@ void Remote::InitCMData()
(CMHandlerFunc)OpenSimpleResponseHandler, &ev_state);
CMregister_handler(ev_state.ReadResponseFormat, (CMHandlerFunc)ReadResponseHandler,
&ev_state);
}
});
}

void Remote::Open(const std::string hostname, const int32_t port, const std::string filename,
Expand Down
35 changes: 15 additions & 20 deletions source/adios2/toolkit/remote/Remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,34 +63,29 @@ class Remote
bool m_Active = false;
};

#ifdef ADIOS2_HAVE_SST
class CManagerSingleton
{
public:
#ifdef ADIOS2_HAVE_SST
static CManagerSingleton &Instance(RemoteCommon::Remote_evpath_state &ev_state);

private:
CManager m_cm = NULL;
#endif
static CManagerSingleton *Instance(bool &first)
RemoteCommon::Remote_evpath_state internalEvState;
CManagerSingleton()
{
static std::mutex init_mutex;
const std::lock_guard<std::mutex> lock(init_mutex);
static CManagerSingleton *ptr = new CManagerSingleton();
static bool internal_first = true;
first = internal_first;
internal_first = false;
return ptr;
m_cm = CManager_create();
internalEvState.cm = m_cm;
RegisterFormats(internalEvState);
CMfork_comm_thread(internalEvState.cm);
}

protected:
#ifdef ADIOS2_HAVE_SST
CManagerSingleton() { m_cm = CManager_create(); }

~CManagerSingleton() { CManager_close(m_cm); }
#else
CManagerSingleton() {}

~CManagerSingleton() {}
#endif
~CManagerSingleton()
{
CManager_close(m_cm);
}
};
#endif

} // end namespace adios2

Expand Down

0 comments on commit f1cfc89

Please sign in to comment.