Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mutex lock error in logging utils #478

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading