Suggestion: AtomicBits, SPSC overwrite atomic queue, LeapSync
Several generic patterns, not available in ETL, but may be useful. All atomic-based, without other platform dependencies. Intended to use for both threads and interrupts interop.
Src: https://github.com/pdsink/pdsink/tree/master/src/utils Tests: https://github.com/pdsink/pdsink/tree/master/test
- AtomicBits - a pack of atomic flags, with access sugar
- SPSC overwrite atomic queue - similar to ETL's SPSC atomic queue, but drops the oldest on overflow instead of failing. Also have methods to reset from the producer and the consumer.
- LeapSync - simple non-queued requests pass between threads/interrupts with repeated requests check.
IMHO AtomicBits & Queue are useful. LeapSync - may be, not sure.
Thanks, they look interesting.
Refactored LeapSink. Now sure about it :)
- Correct and clear logic without compromises. Param fetch is guaranteed to be consistent via 2-phase commits.
The concrete implementation can be improved by adding support for multiple parameters and relaxing memory order. But, TBH, for targeted use, that's not much needed.
Now all three patterns should be fine.
The only trade-off is in SPSC overwrite atomic queue. IF the consumer dies, and the version counter goes too far (> max int32 distance), then the consumer can get garbage. IMHO, a reasonable price for having a lockless SPSC queue without platform-specific dependencies & usable in interrupts. The only requirement is having lockless atomics, but that's just C++11 and above - IMHO good coverage for ETL users.
Also, reset methods can be merged into a single one. But I'm not 100% sure about that, and left it separate for now.