SA_Logger
Sapphire's Suite's C++ Logger.
Loading...
Searching...
No Matches
RingBuffer.hpp
Go to the documentation of this file.
1// Copyright (c) 2024 Sapphire's Suite. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_LOGGER_RING_BUFFER_GUARD
6#define SAPPHIRE_LOGGER_RING_BUFFER_GUARD
7
8#include <atomic>
9#include <thread>
10
22namespace SA
23{
29 template <typename T>
31 {
33 T* mHandleBuffer = nullptr;
34
36 std::atomic<bool>* mPushCompleted = nullptr;
37
38 const uint32_t mCapacity = 0;
39
40 std::atomic<uint64_t> mPushCursor = 0u;
41 std::atomic<uint64_t> mPopCursor = 0u;
42
43 public:
49 RingBuffer(uint32_t _capacity = 32);
50
56
63 void Push(T&& _obj);
64
72 bool Pop(T& _obj, std::atomic<bool>& _bIsRunning);
73
75 uint32_t Size() const noexcept;
76
78 uint32_t Capacity() const noexcept;
79
81 bool IsEmpty() const noexcept;
82 };
83}
84
85
88#include "RindBuffer.inl"
89
90#endif // SAPPHIRE_LOGGER_RING_BUFFER_GUARD
RingBuffer class implementation.
Definition RingBuffer.hpp:31
bool Pop(T &_obj, std::atomic< bool > &_bIsRunning)
Pop an object from the queue. Yield current thread if queue is empty.
bool IsEmpty() const noexcept
Whether the queue is empty.
uint32_t Capacity() const noexcept
Maximum capacity of the queue.
RingBuffer(uint32_t _capacity=32)
Value constructor
uint32_t Size() const noexcept
Current size of the queue.
void Push(T &&_obj)
Push an object to the queue Yield current thread if queue is full.