Uses atomic booleans for thread safety
Replaces mutex with atomic booleans in DixonNodeState for improved thread safety. This eliminates the need for explicit locking in the connected_ and brainRunning_ accessors, reducing overhead and potential for deadlocks. Updates version file.
This commit is contained in:
parent
1da934ba3c
commit
2ccbd2f307
3 changed files with 4 additions and 9 deletions
|
|
@ -8,24 +8,20 @@ DixonNodeState& DixonNodeState::instance()
|
||||||
|
|
||||||
void DixonNodeState::setConnected(bool value)
|
void DixonNodeState::setConnected(bool value)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
|
||||||
connected_ = value;
|
connected_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DixonNodeState::isConnected() const
|
bool DixonNodeState::isConnected() const
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
|
||||||
return connected_;
|
return connected_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DixonNodeState::setBrainRunning(bool value)
|
void DixonNodeState::setBrainRunning(bool value)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
|
||||||
brainRunning_ = value;
|
brainRunning_ = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DixonNodeState::isBrainRunning() const
|
bool DixonNodeState::isBrainRunning() const
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(mutex_);
|
|
||||||
return brainRunning_;
|
return brainRunning_;
|
||||||
}
|
}
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <mutex>
|
#include<atomic>
|
||||||
|
|
||||||
class DixonNodeState
|
class DixonNodeState
|
||||||
{
|
{
|
||||||
|
|
@ -21,7 +21,6 @@ private:
|
||||||
DixonNodeState() = default;
|
DixonNodeState() = default;
|
||||||
~DixonNodeState() = default;
|
~DixonNodeState() = default;
|
||||||
|
|
||||||
mutable std::mutex mutex_;
|
std::atomic<bool> connected_ = false;
|
||||||
bool connected_ = false;
|
std::atomic<bool> brainRunning_ = false;
|
||||||
bool brainRunning_ = false;
|
|
||||||
};
|
};
|
||||||
|
|
@ -1 +1 @@
|
||||||
1.0.10
|
1.0.12
|
||||||
Loading…
Reference in a new issue