Skip to content

Commit

Permalink
performance(BipartiteBuf): Only load the atomic invalidate index when…
Browse files Browse the repository at this point in the history
… necessary

We don't care about the previous value of i if the write has wrapped, so we can only load it if it hasn't.
  • Loading branch information
DNedic committed Mar 21, 2024
1 parent bc6affd commit f13961a
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lockfree/spsc/bipartite_buf_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,16 @@ T *BipartiteBuf<T, size>::WriteAcquire(const size_t free_required) {

template <typename T, size_t size>
void BipartiteBuf<T, size>::WriteRelease(const size_t written) {
/* Preload variables with adequate memory ordering */
size_t w = _w.load(std::memory_order_relaxed);
size_t i = _i.load(std::memory_order_relaxed);

/* If the write wrapped set the invalidate index and reset write index*/
size_t i;
if (_write_wrapped) {
_write_wrapped = false;
i = w;
w = 0U;
} else {
i = _i.load(std::memory_order_relaxed);
}

/* Increment the write index */
Expand Down

0 comments on commit f13961a

Please sign in to comment.