From 28a0ca8fcfc4ec7e2eed8707a1f5a90f52d19e08 Mon Sep 17 00:00:00 2001 From: WarmUpTill <19472752+WarmUpTill@users.noreply.github.com> Date: Sat, 13 Jun 2026 23:24:21 +0200 Subject: [PATCH] Expose API to notify about variable value change --- lib/variables/variable.cpp | 20 ++++++++++++-------- lib/variables/variable.hpp | 8 ++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) 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;