mirror of
https://github.com/FEX-Emu/FEX.git
synced 2026-10-06 13:00:15 +02:00
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:
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
|
||||
Reference in new issue
Block a user