diff --git a/glass/src/lib/native/include/glass/DataSource.h b/glass/src/lib/native/include/glass/DataSource.h index 011155e697..7e0c673054 100644 --- a/glass/src/lib/native/include/glass/DataSource.h +++ b/glass/src/lib/native/include/glass/DataSource.h @@ -11,6 +11,7 @@ #include #include +#include namespace glass { @@ -37,12 +38,21 @@ class DataSource { bool IsDigital() const { return m_digital; } void SetValue(double value, int64_t time = 0) { + std::scoped_lock lock{m_valueMutex}; m_value = value; m_valueTime = time; valueChanged(value, time); } - double GetValue() const { return m_value; } - int64_t GetValueTime() const { return m_valueTime; } + + double GetValue() const { + std::scoped_lock lock{m_valueMutex}; + return m_value; + } + + int64_t GetValueTime() const { + std::scoped_lock lock{m_valueMutex}; + return m_valueTime; + } // drag source helpers void LabelText(const char* label, const char* fmt, ...) const IM_FMTARGS(3); @@ -59,7 +69,7 @@ class DataSource { ImGuiInputTextFlags flags = 0) const; void EmitDrag(ImGuiDragDropFlags flags = 0) const; - wpi::sig::Signal valueChanged; + wpi::sig::SignalBase valueChanged; static DataSource* Find(std::string_view id); @@ -69,6 +79,7 @@ class DataSource { std::string m_id; std::string& m_name; bool m_digital = false; + mutable wpi::spinlock m_valueMutex; double m_value = 0; int64_t m_valueTime = 0; };