Skip to content

Commit 9a7585b

Browse files
committed
Add [[unlikely]] attribute
Add `[[unlikely]]` attribute to conditions where cached indexes need to be updated. This is `C++20` feature which this library needs anyway.
1 parent c515768 commit 9a7585b

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

include/LockFreeSpscQueue.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ class LockFreeSpscQueue
555555
size_t available_items
556556
= m_consumer_data.cached_write_pos - current_read_pos;
557557

558-
if (available_items < num_items_to_read) {
558+
if (available_items < num_items_to_read) [[unlikely]] {
559559
// "Slow path": our cache is out of date.
560560
// Perform an expensive acquire load to get the true position from the producer.
561561
m_consumer_data.cached_write_pos
@@ -713,7 +713,7 @@ class LockFreeSpscQueue
713713
// 64-bit indices wrap around, due to the defined behavior of unsigned
714714
// integer arithmetic.
715715

716-
if (available_space < num_items_to_write) {
716+
if (available_space < num_items_to_write) [[unlikely]] {
717717
// "Slow path": our cache is out of date.
718718
// Perform an expensive acquire load to get the true position from the consumer.
719719
m_producer_data.cached_read_pos

0 commit comments

Comments
 (0)