diff options
| author | Jesse Meyer <jesse.r.meyer@me.com> | 2026-02-03 20:52:52 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-03 20:52:52 -0500 |
| commit | b8276065f9296754d1e76e25d6661b7b5567e3e1 (patch) | |
| tree | 7b8783d43193c16e4ef393a175fede50a8fe52dd /src/thread_pool.cpp | |
| parent | bd6148dd6b77920cf64fea8804b205e8257e8a66 (diff) | |
| parent | 270df36468df8f89e1ac944205272469142c7a65 (diff) | |
Merge branch 'master' into lto-support
Diffstat (limited to 'src/thread_pool.cpp')
| -rw-r--r-- | src/thread_pool.cpp | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/thread_pool.cpp b/src/thread_pool.cpp index ca6483fd9..a0afbd269 100644 --- a/src/thread_pool.cpp +++ b/src/thread_pool.cpp @@ -1,5 +1,15 @@ // thread_pool.cpp +// TODO(bill): make work on MSVC +// #if defined(__SANITIZE_THREAD__) || (defined(__has_feature) && __has_feature(thread_sanitizer)) +// #include <sanitizer/tsan_interface.h> +// #define TSAN_RELEASE(addr) __tsan_release(addr) +// #define TSAN_ACQUIRE(addr) __tsan_acquire(addr) +// #else +#define TSAN_RELEASE(addr) +#define TSAN_ACQUIRE(addr) +// #endif + struct WorkerTask; struct ThreadPool; @@ -88,6 +98,7 @@ void thread_pool_queue_push(Thread *thread, WorkerTask task) { } cur_ring->buffer[bot % cur_ring->size] = task; + TSAN_RELEASE(cur_ring->buffer[bot % cur_ring->size]); std::atomic_thread_fence(std::memory_order_release); thread->queue.bottom.store(bot + 1, std::memory_order_relaxed); @@ -108,6 +119,7 @@ GrabState thread_pool_queue_take(Thread *thread, WorkerTask *task) { if (top <= bot) { // Queue is not empty + TSAN_ACQUIRE(cur_ring->buffer[bot % cur_ring->size]); *task = cur_ring->buffer[bot % cur_ring->size]; if (top == bot) { // Only one entry left in queue @@ -139,6 +151,8 @@ GrabState thread_pool_queue_steal(Thread *thread, WorkerTask *task) { if (top < bot) { // Queue is not empty TaskRingBuffer *cur_ring = thread->queue.ring.load(std::memory_order_consume); + + TSAN_ACQUIRE(&cur_ring->buffer[top % cur_ring->size]); *task = cur_ring->buffer[top % cur_ring->size]; if (!thread->queue.top.compare_exchange_strong(top, top + 1, std::memory_order_seq_cst, std::memory_order_relaxed)) { |