OS  v1.7.5
Documentation
Loading...
Searching...
No Matches
queue.hpp
1#ifndef QOS_CPP_QUEUE
2#define QOS_CPP_QUEUE
3
4#include "include/types.hpp"
5
6namespace qOS {
7
17 enum class queueSendMode {
18 TO_BACK, /*< to indicate whether the item in the queue should be sent to the back. */
19 TO_FRONT /*< to indicate whether the item in the queue should be sent to the front. */
20 };
21
44 class queue {
45 private:
46 uint8_t *head{ nullptr };
47 uint8_t *tail{ nullptr };
48 uint8_t *writer{ nullptr };
49 uint8_t *reader{ nullptr };
50 volatile size_t itemsWaiting = 0U;
51 size_t itemsCount = 0U;
52 size_t itemSize = 0U;
53 void moveReader( void ) noexcept;
54 void copyDataFromQueue( void * const dst ) noexcept;
55 void copyDataToQueue( const void *itemToQueue, const queueSendMode xPosition ) noexcept;
56 queue( queue const& ) = delete;
57 void operator=( queue const& ) = delete;
58 public:
59 queue() = default;
61 virtual ~queue() {}
71 bool setup( void *pData, const size_t size, const size_t count ) noexcept;
80 template <typename T>
81 bool setup( void *pData, const size_t count ) noexcept
82 {
83 return setup( pData, sizeof(T), count );
84 }
88 void reset( void ) noexcept;
93 bool isEmpty( void ) const noexcept;
98 bool isFull( void ) const noexcept;
103 size_t count( void ) const noexcept;
109 size_t itemsAvailable( void ) const noexcept;
115 bool removeFront( void ) noexcept;
126 bool receive( void *dst ) noexcept;
139 bool send( void *itemToQueue, const queueSendMode pos = queueSendMode::TO_BACK ) noexcept;
144 void* peek( void ) const noexcept;
149 bool isInitialized( void ) const noexcept;
154 size_t getItemSize( void ) const noexcept;
155 };
156
158}
159
160
161#endif /*QOS_CPP_QUEUE*/
A Queue object.
Definition queue.hpp:44
bool receive(void *dst) noexcept
Receive an item from a queue (and removes it). The item is received by copy so a buffer of adequate s...
void * peek(void) const noexcept
Looks at the data from the front of the Queue without removing it.
size_t itemsAvailable(void) const noexcept
Returns the number of available slots to hold items inside the queue.
queue()=default
bool isEmpty(void) const noexcept
Returns the empty status of the Queue.
size_t getItemSize(void) const noexcept
Get the size(in bytes) used for every item in the queue.
void reset(void) noexcept
Resets a queue to its original empty state.
size_t count(void) const noexcept
Returns the number of items in the Queue.
bool isInitialized(void) const noexcept
Check if the queue is already initialized by using queue::setup()
bool setup(void *pData, const size_t count) noexcept
Configures a Queue. Here, the RAM used to hold the queue data pData is statically allocated at compil...
Definition queue.hpp:81
bool setup(void *pData, const size_t size, const size_t count) noexcept
Configures a Queue. Here, the RAM used to hold the queue data pData is statically allocated at compil...
bool isFull(void) const noexcept
Returns the full status of the Queue.
bool send(void *itemToQueue, const queueSendMode pos=queueSendMode::TO_BACK) noexcept
Post an item to the the queue. The item is queued by copy, not by reference.
bool removeFront(void) noexcept
Remove the data located at the front of the Queue.
queueSendMode
An enum that defines the modes in which a item should be inserted in to a queue.
Definition queue.hpp:17
OS/Kernel interfaces.
Definition bytebuffer.hpp:7