Files
FEX-Emu--FEX/FEXHeaderUtils/FEXHeaderUtils/RingBuffer.h
T
Ryan Houdek 118faa5380 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.
2025-05-02 01:19:00 -07:00

22 lines
563 B
C++

#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