FHU: Add a non-block thread local ringbuffer

I keep rewriting this thing when I want to see some history on
something. Throw it in a FHU utility so I can stop wasting my time.
This commit is contained in:
Ryan Houdek committed 2025-05-02 01:19:00 -07:00
1 parent 4f2d2e646e
commit 118faa5380
1 file changed
+21
@@ -0,0 +1,21 @@
#pragma once
#include <bit>
#include <cstddef>
namespace FHU {
// This is a fast thread-local non-blocking ring-buffer.
// Very useful for debugging purposes to see the history of something.
template<typename T, size_t Elements>
requires (std::has_single_bit(Elements) && std::is_trivially_copyable_v<T>)
class [[deprecated("Not for production use")]] NonBlockRingBuffer final {
public:
void emplace(T Val) {
Ring[Current] = Val;
Current = (Current + 1) & (Elements - 1);
}
private:
T Ring[Elements] {};
size_t Current {};
};
} // namespace FHU