summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Egge <Tor.Egge@yahooinc.com>2022-12-06 19:56:25 +0100
committerGitHub <noreply@github.com>2022-12-06 19:56:25 +0100
commit6961231415aa1e9c7a57e47567c24f1e0bdb3599 (patch)
treef0bfef05c432c471fc6994d85bfb94b8a6ae0ca6
parent4d1718b458252859355775d567d6ba45c8d67723 (diff)
parent6ddd99f963588f2d3b1bd575e0431ecdbf673397 (diff)
Merge pull request #25137 from vespa-engine/toregge/use-atomic-thread-pointer-in-runnable
Use atomic thread pointer in runnable.
-rw-r--r--fastos/src/vespa/fastos/thread.cpp2
-rw-r--r--fastos/src/vespa/fastos/thread.h8
2 files changed, 5 insertions, 5 deletions
diff --git a/fastos/src/vespa/fastos/thread.cpp b/fastos/src/vespa/fastos/thread.cpp
index 7695ce3342e..d172977b222 100644
--- a/fastos/src/vespa/fastos/thread.cpp
+++ b/fastos/src/vespa/fastos/thread.cpp
@@ -308,7 +308,7 @@ void FastOS_ThreadInterface::Dispatch(FastOS_Runnable *newOwner, void *arg)
_owner = newOwner;
_startArg = arg;
// Set _thread variable before NewThread returns
- _owner->_thread = this;
+ _owner->_thread.store(this, std::memory_order_release);
// It is safe to signal after the unlock since _liveCond is still held
// so the signalled thread still exists.
diff --git a/fastos/src/vespa/fastos/thread.h b/fastos/src/vespa/fastos/thread.h
index 95737e9d079..a8cf12825eb 100644
--- a/fastos/src/vespa/fastos/thread.h
+++ b/fastos/src/vespa/fastos/thread.h
@@ -455,7 +455,7 @@ class FastOS_Runnable
{
private:
friend class FastOS_ThreadInterface;
- FastOS_ThreadInterface *_thread;
+ std::atomic<FastOS_ThreadInterface*> _thread;
public:
FastOS_Runnable(const FastOS_Runnable&) = delete;
@@ -482,9 +482,9 @@ public:
*/
virtual void Run(FastOS_ThreadInterface *thisThread, void *arguments)=0;
- FastOS_ThreadInterface *GetThread() { return _thread; }
- const FastOS_ThreadInterface *GetThread() const { return _thread; }
- bool HasThread() const { return _thread != nullptr; }
+ FastOS_ThreadInterface *GetThread() noexcept { return _thread.load(std::memory_order_acquire); }
+ const FastOS_ThreadInterface *GetThread() const noexcept { return _thread.load(std::memory_order_acquire); }
+ bool HasThread() const noexcept { return GetThread() != nullptr; }
};
#include <vespa/fastos/unix_thread.h>