diff --git a/lib/variables/variable.cpp b/lib/variables/variable.cpp index 2f2510a1..249aab1d 100644 --- a/lib/variables/variable.cpp +++ b/lib/variables/variable.cpp @@ -108,16 +108,20 @@ std::optional Variable::IntValue() const void Variable::SetValue(const std::string &value) { - std::lock_guard lock(_mutex); - _previousValue = _value; - _value = value; + { + std::lock_guard lock(_mutex); + _previousValue = _value; + _value = value; - UpdateLastUsed(); - if (_previousValue != _value) { - _lastChanged = std::chrono::high_resolution_clock::now(); - ++_valueChangeCount; + UpdateLastUsed(); + if (_previousValue != _value) { + _lastChanged = + std::chrono::high_resolution_clock::now(); + ++_valueChangeCount; + } + setLastVariableChangeTime(); } - setLastVariableChangeTime(); + _cv.notify_all(); } void Variable::SetValue(double value) diff --git a/lib/variables/variable.hpp b/lib/variables/variable.hpp index 970ce74e..5d70f096 100644 --- a/lib/variables/variable.hpp +++ b/lib/variables/variable.hpp @@ -3,6 +3,7 @@ #include "item-selection-helpers.hpp" #include "resizing-text-edit.hpp" +#include #include #include #include @@ -43,6 +44,11 @@ public: std::optional GetSecondsSinceLastUse() const; std::optional GetSecondsSinceLastChange() const; void MarkAsUsed() const; + EXPORT std::condition_variable &GetCV() { return _cv; } + EXPORT std::unique_lock GetCVLock() + { + return std::unique_lock(_cvMutex); + } private: SaveAction _saveAction = SaveAction::DONT_SAVE; @@ -53,6 +59,8 @@ private: mutable std::chrono::high_resolution_clock::time_point _lastUsed; mutable std::chrono::high_resolution_clock::time_point _lastChanged; mutable std::mutex _mutex; + std::mutex _cvMutex; + std::condition_variable _cv; void UpdateLastUsed() const;