News for hackers. Stuff that matters.
Re:Show HN: Embedded Ring Buffer C++98 by injinj on Monday June 07, 2021 @05:27AM (#27420608)
One thing I found useful is instead of

  volatile T member;

  T access( void ) { return member; }
Use volatile on the functions instead:

  T member;

  T access( void ) volatile { return member; }
This has causes all access to this-> within the function to be volatile, including read_position, write_position, overrun_flag and data[].

When inlining these functions within other parts of the code, the compiler can hoist reads into registers from the non-volatile members unless you add the compiler barrier that @ghhhhhk8899jj mentioned.

There are no comments on this comment yet.