diff options
author | - <unknown> | 2022-06-22 16:30:36 -0400 |
---|---|---|
committer | Matthew Gregan <[email protected]> | 2022-06-23 14:21:36 +1200 |
commit | 744d638ba702dd4d364d03c423556dfa5517e3fa (patch) | |
tree | b6bca601a7490ac04468f1936ba8578c03e1feb8 /src/cubeb_ringbuffer.h | |
parent | 3dd0c44a39a95ef967ae1e919034ff675dd36da8 (diff) | |
download | cubeb-744d638ba702dd4d364d03c423556dfa5517e3fa.tar.gz cubeb-744d638ba702dd4d364d03c423556dfa5517e3fa.zip |
fix threading errors
rearrange the cross-thread load to be the second load; being a little late may cause it to be lucky! (this probably doesn't matter)
Diffstat (limited to 'src/cubeb_ringbuffer.h')
-rw-r--r-- | src/cubeb_ringbuffer.h | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/cubeb_ringbuffer.h b/src/cubeb_ringbuffer.h index 2838184..f020351 100644 --- a/src/cubeb_ringbuffer.h +++ b/src/cubeb_ringbuffer.h @@ -110,8 +110,8 @@ public: assert_correct_thread(producer_id); #endif - int rd_idx = read_index_.load(std::memory_order_relaxed); int wr_idx = write_index_.load(std::memory_order_relaxed); + int rd_idx = read_index_.load(std::memory_order_acquire); if (full_internal(rd_idx, wr_idx)) { return 0; @@ -154,8 +154,8 @@ public: assert_correct_thread(consumer_id); #endif - int wr_idx = write_index_.load(std::memory_order_acquire); int rd_idx = read_index_.load(std::memory_order_relaxed); + int wr_idx = write_index_.load(std::memory_order_acquire); if (empty_internal(rd_idx, wr_idx)) { return 0; @@ -172,7 +172,7 @@ public: } read_index_.store(increment_index(rd_idx, to_read), - std::memory_order_relaxed); + std::memory_order_release); return to_read; } @@ -190,7 +190,7 @@ public: #endif return available_read_internal( read_index_.load(std::memory_order_relaxed), - write_index_.load(std::memory_order_relaxed)); + write_index_.load(std::memory_order_acquire)); } /** * Get the number of available elements for consuming. @@ -205,7 +205,7 @@ public: assert_correct_thread(producer_id); #endif return available_write_internal( - read_index_.load(std::memory_order_relaxed), + read_index_.load(std::memory_order_acquire), write_index_.load(std::memory_order_relaxed)); } /** |