diff options
author | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-02-18 14:32:53 +0000 |
---|---|---|
committer | Tor Brede Vekterli <vekterli@yahooinc.com> | 2022-02-18 15:38:34 +0000 |
commit | 184ba3ac5ddece6ee27cc54b045677d6c9e298e2 (patch) | |
tree | 1796e9939cf7e50e739dbe2b82d01d3f13b6faf7 /storageframework | |
parent | 9a06290d284f2fdea48b8b9ff089521104f2793f (diff) |
Make storage framework thread tick ring buffer thread safe
Diffstat (limited to 'storageframework')
-rw-r--r-- | storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp | 11 | ||||
-rw-r--r-- | storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h | 2 |
2 files changed, 8 insertions, 5 deletions
diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp index 7281c55ba25..b8ef8e4610b 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp +++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.cpp @@ -3,10 +3,13 @@ #include "threadimpl.h" #include "threadpoolimpl.h" #include <vespa/storageframework/generic/clock/clock.h> +#include <vespa/vespalib/util/atomic.h> #include <vespa/log/bufferedlogger.h> LOG_SETUP(".framework.thread.impl"); +using namespace vespalib::atomic; + namespace storage::framework::defaultimplementation { ThreadImpl::ThreadImpl(ThreadPoolImpl& pool, @@ -27,7 +30,7 @@ ThreadImpl::ThreadImpl(ThreadPoolImpl& pool, _thread(*this), _cpu_category(cpu_category) { - _tickData[_tickDataPtr]._lastTick = pool.getClock().getMonotonicTime(); + _tickData[load_relaxed(_tickDataPtr)]._lastTick = pool.getClock().getMonotonicTime(); _thread.start(_pool.getThreadPool()); } @@ -105,15 +108,15 @@ ThreadImpl::registerTick(CycleType cycleType, vespalib::steady_time now) ThreadTickData ThreadImpl::getTickData() const { - return _tickData[_tickDataPtr].loadRelaxed(); + return _tickData[load_acquire(_tickDataPtr)].loadRelaxed(); } void ThreadImpl::setTickData(const ThreadTickData& tickData) { - uint32_t nextData = (_tickDataPtr + 1) % _tickData.size(); + uint32_t nextData = (load_relaxed(_tickDataPtr) + 1) % _tickData.size(); _tickData[nextData].storeRelaxed(tickData); - _tickDataPtr = nextData; + store_release(_tickDataPtr, nextData); } ThreadTickData diff --git a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h index e6f0a21ea20..46a9412bf67 100644 --- a/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h +++ b/storageframework/src/vespa/storageframework/defaultimplementation/thread/threadimpl.h @@ -49,7 +49,7 @@ class ThreadImpl : public Thread Runnable& _runnable; ThreadProperties _properties; std::array<AtomicThreadTickData, 3> _tickData; - uint32_t _tickDataPtr; + std::atomic<uint32_t> _tickDataPtr; std::atomic<bool> _interrupted; bool _joined; BackendThread _thread; |