mirror of
https://github.com/usatiuk/psil.git
synced 2025-10-28 18:57:48 +01:00
remove mutex in options
as it shouldn't be written to concurrently
This commit is contained in:
@@ -18,7 +18,6 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
static T get(const std::string &opt) {
|
static T get(const std::string &opt) {
|
||||||
Options &o = get();
|
Options &o = get();
|
||||||
std::shared_lock l(o._mutex);
|
|
||||||
if (_defaults.find(opt) == _defaults.end()) throw std::invalid_argument("Unknown option " + opt);
|
if (_defaults.find(opt) == _defaults.end()) throw std::invalid_argument("Unknown option " + opt);
|
||||||
if (!std::holds_alternative<T>(_defaults.at(opt))) throw std::invalid_argument("Bad option type " + opt);
|
if (!std::holds_alternative<T>(_defaults.at(opt))) throw std::invalid_argument("Bad option type " + opt);
|
||||||
return std::get<T>(o._current.at(opt));
|
return std::get<T>(o._current.at(opt));
|
||||||
@@ -27,7 +26,6 @@ public:
|
|||||||
template<typename T>
|
template<typename T>
|
||||||
static void set(const std::string &opt, const T &val) {
|
static void set(const std::string &opt, const T &val) {
|
||||||
Options &o = get();
|
Options &o = get();
|
||||||
std::lock_guard l(o._mutex);
|
|
||||||
if (_defaults.find(opt) == _defaults.end()) throw std::invalid_argument("Unknown option " + opt);
|
if (_defaults.find(opt) == _defaults.end()) throw std::invalid_argument("Unknown option " + opt);
|
||||||
if (!std::holds_alternative<T>(_defaults.at(opt))) throw std::invalid_argument("Bad option type " + opt);
|
if (!std::holds_alternative<T>(_defaults.at(opt))) throw std::invalid_argument("Bad option type " + opt);
|
||||||
o._current[opt] = val;
|
o._current[opt] = val;
|
||||||
@@ -44,7 +42,6 @@ private:
|
|||||||
{"repl", true}};
|
{"repl", true}};
|
||||||
|
|
||||||
std::unordered_map<std::string, std::variant<size_t, bool>> _current = _defaults;
|
std::unordered_map<std::string, std::variant<size_t, bool>> _current = _defaults;
|
||||||
std::shared_mutex _mutex;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,4 @@ Options &Options::get() {
|
|||||||
return opts;
|
return opts;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Options::reset() {
|
void Options::reset() { get()._current = _defaults; }
|
||||||
std::lock_guard l(get()._mutex);
|
|
||||||
get()._current = _defaults;
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user