summaryrefslogtreecommitdiffstats
path: root/fastos
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@oath.com>2019-01-10 14:43:41 +0000
committerTor Brede Vekterli <vekterli@oath.com>2019-01-10 14:43:41 +0000
commitc540dd41dc5af04b4e81c6f82e894740cdde9dad (patch)
treeb99aed1d5073b528bda68083ca625eb0c21595f6 /fastos
parentc5850bb67b84120c92c8ba514dbf0e4084389947 (diff)
Use relaxed atomics for FastOS_ThreadInterface break flag
Diffstat (limited to 'fastos')
-rw-r--r--fastos/src/vespa/fastos/thread.cpp4
-rw-r--r--fastos/src/vespa/fastos/thread.h5
2 files changed, 5 insertions, 4 deletions
diff --git a/fastos/src/vespa/fastos/thread.cpp b/fastos/src/vespa/fastos/thread.cpp
index 5e3400b70e3..3df8fa584a7 100644
--- a/fastos/src/vespa/fastos/thread.cpp
+++ b/fastos/src/vespa/fastos/thread.cpp
@@ -266,7 +266,7 @@ void FastOS_ThreadInterface::Hook ()
}
_owner = nullptr;
_startArg = nullptr;
- _breakFlag = false;
+ _breakFlag.store(false, std::memory_order_relaxed);
finished = _pool->isClosed();
dispatchedGuard.unlock(); // END lock
@@ -322,7 +322,7 @@ void FastOS_ThreadInterface::Dispatch(FastOS_Runnable *newOwner, void *arg)
void FastOS_ThreadInterface::SetBreakFlag()
{
std::lock_guard<std::mutex> dispatchedGuard(_dispatchedMutex);
- _breakFlag = true;
+ _breakFlag.store(true, std::memory_order_relaxed);
_dispatchedCond.notify_one();
}
diff --git a/fastos/src/vespa/fastos/thread.h b/fastos/src/vespa/fastos/thread.h
index 2726efe3cf0..c025a48d563 100644
--- a/fastos/src/vespa/fastos/thread.h
+++ b/fastos/src/vespa/fastos/thread.h
@@ -12,6 +12,7 @@
#include "types.h"
+#include <atomic>
#include <mutex>
#include <condition_variable>
@@ -294,7 +295,7 @@ protected:
/**
* Break flag. If true, the thread should exit.
*/
- bool _breakFlag;
+ std::atomic<bool> _breakFlag;
/**
* Is this thread active or free in the threadpool?
@@ -385,7 +386,7 @@ public:
*/
bool GetBreakFlag () const
{
- return _breakFlag;
+ return _breakFlag.load(std::memory_order_relaxed);
}
/**