Skip to content

Commit

Permalink
Fix mutex lock error in logging utils (#478)
Browse files Browse the repository at this point in the history
  • Loading branch information
jparismorgan authored Aug 6, 2024
1 parent 3488a50 commit ddf0be6
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/include/utils/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,11 @@ class timing_data_class {
* @return The singleton instance.
*/
static timing_data_class& get_instance() {
static timing_data_class instance;
return instance;
static std::once_flag flag;
// This will leak, but it's okay - it's the Trusty Leaky Singleton pattern.
static timing_data_class* instance;
std::call_once(flag, []() { instance = new timing_data_class(); });
return *instance;
}

/**
Expand Down Expand Up @@ -384,8 +387,11 @@ class memory_data {
* @return Reference to the singleton instance of the class.
*/
static memory_data& get_instance() {
static memory_data instance;
return instance;
static std::once_flag flag;
// This will leak, but it's okay - it's the Trusty Leaky Singleton pattern.
static memory_data* instance;
std::call_once(flag, []() { instance = new memory_data(); });
return *instance;
}

/**
Expand Down Expand Up @@ -499,8 +505,11 @@ class count_data {
* @return Reference to the singleton instance of the class.
*/
static count_data& get_instance() {
static count_data instance;
return instance;
static std::once_flag flag;
// This will leak, but it's okay - it's the Trusty Leaky Singleton pattern.
static count_data* instance;
std::call_once(flag, []() { instance = new count_data(); });
return *instance;
}

/**
Expand Down

0 comments on commit ddf0be6

Please sign in to comment.