Skip to content

Commit

Permalink
* some more mutexes
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan Walter committed Nov 5, 2024
1 parent 8b36ded commit 85eb474
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
10 changes: 10 additions & 0 deletions common/misc/GlobalSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ std::mutex& GlobalSettings::mutex() {
return _mutex;
}

std::mutex& GlobalSettings::defaults_mutex() {
static std::mutex _mutex;
return _mutex;
}

/**
* GlobalSettings implementation
*/
Expand Down Expand Up @@ -51,32 +56,37 @@ std::shared_ptr<const sprite::PropertyType> GlobalSettings::at(std::string_view
}

sprite::Map& GlobalSettings::current_defaults() {
std::unique_lock guard(defaults_mutex());
if (!instance())
throw U_EXCEPTION("No GlobalSettings instance.");
return instance()->_current_defaults;
}

void GlobalSettings::set_current_defaults(const sprite::Map& map) {
std::unique_lock guard(defaults_mutex());
if (!instance())
throw U_EXCEPTION("No GlobalSettings instance.");
instance()->_current_defaults.set_print_by_default(false);
instance()->_current_defaults = map;
}

sprite::Map& GlobalSettings::current_defaults_with_config() {
std::unique_lock guard(defaults_mutex());
if (!instance())
throw U_EXCEPTION("No GlobalSettings instance.");
return instance()->_current_defaults_with_config;
}

void GlobalSettings::set_current_defaults_with_config(const sprite::Map& map) {
std::unique_lock guard(defaults_mutex());
if (!instance())
throw U_EXCEPTION("No GlobalSettings instance.");
instance()->_current_defaults_with_config.set_print_by_default(false);
instance()->_current_defaults_with_config = map;
}

const sprite::Map& GlobalSettings::defaults() {
std::unique_lock guard(defaults_mutex());
if (!instance())
throw U_EXCEPTION("No GlobalSettings instance.");
return instance()->_defaults;
Expand Down
1 change: 1 addition & 0 deletions common/misc/GlobalSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace cmn {

//friend struct detail::g_GSettingsSingletonStruct;
static std::mutex& mutex();
static std::mutex& defaults_mutex();

public:
GlobalSettings();
Expand Down

0 comments on commit 85eb474

Please sign in to comment.