Skip to content

Commit

Permalink
Defer loading the invalidate index until it is actually needed
Browse files Browse the repository at this point in the history
  • Loading branch information
DNedic committed Jun 5, 2023
1 parent 5a0862b commit 6fc1999
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lfbb/src/lfbb.c
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ uint8_t *LFBB_ReadAcquire(LFBB_Inst_Type *inst, size_t *available) {
/* Preload variables with adequate memory ordering */
const size_t r = atomic_load_explicit(&inst->r, memory_order_relaxed);
const size_t w = atomic_load_explicit(&inst->w, memory_order_acquire);
const size_t i = atomic_load_explicit(&inst->i, memory_order_relaxed);

/* When read and write indexes are equal, the buffer is empty */
if (r == w) {
Expand All @@ -158,6 +157,7 @@ uint8_t *LFBB_ReadAcquire(LFBB_Inst_Type *inst, size_t *available) {
}

/* Read index reached the invalidate index, make the read wrap */
const size_t i = atomic_load_explicit(&inst->i, memory_order_relaxed);
if (r == i) {
inst->read_wrapped = true;
*available = w;
Expand Down

0 comments on commit 6fc1999

Please sign in to comment.