Skip to content

Commit

Permalink
Tweak singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
eisenhauer committed Sep 28, 2023
1 parent 91ded86 commit 90dce7e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 19 deletions.
4 changes: 2 additions & 2 deletions source/adios2/toolkit/remote/Remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ 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;
auto CM = CManagerSingleton::Instance(first);
ev_state.cm = CM->m_cm;
RegisterFormats(ev_state);
if (first)
{
Expand Down
20 changes: 3 additions & 17 deletions source/adios2/toolkit/remote/Remote.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,28 +69,15 @@ class CManagerSingleton
#ifdef ADIOS2_HAVE_SST
CManager m_cm = NULL;
#endif
static CManagerSingleton &Instance(bool &first)
static CManagerSingleton *Instance(bool &first)
{
// Since it's a static variable, if the class has already been created,
// it won't be created again.
// And it **is** thread-safe in C++11.
static CManagerSingleton myInstance;
static CManagerSingleton *ptr = new CManagerSingleton();
static bool internal_first = true;
// Return a reference to our instance.

first = internal_first;
internal_first = false;
return myInstance;
return ptr;
}

// delete copy and move constructors and assign operators
CManagerSingleton(CManagerSingleton const &) = delete; // Copy construct
CManagerSingleton(CManagerSingleton &&) = delete; // Move construct
CManagerSingleton &operator=(CManagerSingleton const &) = delete; // Copy assign
CManagerSingleton &operator=(CManagerSingleton &&) = delete; // Move assign

// Any other public methods.

protected:
#ifdef ADIOS2_HAVE_SST
CManagerSingleton() { m_cm = CManager_create(); }
Expand All @@ -101,7 +88,6 @@ class CManagerSingleton

~CManagerSingleton() {}
#endif
// And any other protected methods.
};

} // end namespace adios2
Expand Down

0 comments on commit 90dce7e

Please sign in to comment.