37 ret = pthread_mutex_init(&this->
queueLock,
nullptr);
43 (void) pthread_mutex_destroy(&this->
queueLock);
59 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
62 if (
nullptr != queueHandle) {
64 queueHandle =
nullptr;
68 queueHandle =
new(std::nothrow) QueueHandle;
69 if (
nullptr == queueHandle) {
72 if( !queueHandle->create(depth, msgSize) ) {
77 #if FW_QUEUE_REGISTRATION
78 if (this->s_queueRegistry) {
79 this->s_queueRegistry->regQueue(
this);
88 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
89 if (
nullptr != queueHandle) {
98 pthread_cond_t* queueNotEmpty = &queueHandle->queueNotEmpty;
99 pthread_mutex_t* queueLock = &queueHandle->queueLock;
106 ret = pthread_mutex_lock(queueLock);
111 bool pushSucceeded = queue->
push(buffer, size, priority);
116 ret = pthread_cond_signal(queueNotEmpty);
125 ret = pthread_mutex_unlock(queueLock);
136 pthread_cond_t* queueNotEmpty = &queueHandle->queueNotEmpty;
137 pthread_cond_t* queueNotFull = &queueHandle->queueNotFull;
138 pthread_mutex_t* queueLock = &queueHandle->queueLock;
144 ret = pthread_mutex_lock(queueLock);
149 while( queue->
isFull() ) {
150 ret = pthread_cond_wait(queueNotFull, queueLock);
155 bool pushSucceeded = queue->
push(buffer, size, priority);
165 ret = pthread_cond_signal(queueNotEmpty);
169 ret = pthread_mutex_unlock(queueLock);
180 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
181 BufferQueue* queue = &queueHandle->queue;
183 if (
nullptr == queueHandle) {
187 if (
nullptr == buffer) {
191 if (size < 0 ||
static_cast<NATIVE_UINT_TYPE>(size) > queue->getMsgSize()) {
196 return sendNonBlock(queueHandle, buffer, size, priority);
199 return sendBlock(queueHandle, buffer, size, priority);
205 pthread_mutex_t* queueLock = &queueHandle->queueLock;
206 pthread_cond_t* queueNotFull = &queueHandle->queueNotFull;
216 ret = pthread_mutex_lock(queueLock);
221 bool popSucceeded = queue->
pop(buffer, size, pri);
230 ret = pthread_cond_signal(queueNotFull);
239 else if( size == 0 ) {
250 ret = pthread_mutex_unlock(queueLock);
261 pthread_cond_t* queueNotEmpty = &queueHandle->queueNotEmpty;
262 pthread_cond_t* queueNotFull = &queueHandle->queueNotFull;
263 pthread_mutex_t* queueLock = &queueHandle->queueLock;
273 ret = pthread_mutex_lock(queueLock);
279 ret = pthread_cond_wait(queueNotEmpty, queueLock);
284 bool popSucceeded = queue->
pop(buffer, size, pri);
293 ret = pthread_cond_signal(queueNotFull);
311 ret = pthread_mutex_unlock(queueLock);
325 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
327 if (
nullptr == queueHandle) {
338 return receiveNonBlock(queueHandle, buffer, capacity, actualSize, priority);
341 return receiveBlock(queueHandle, buffer, capacity, actualSize, priority);
345 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
346 if (
nullptr == queueHandle) {
349 BufferQueue* queue = &queueHandle->queue;
350 return queue->getCount();
354 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
355 if (
nullptr == queueHandle) {
358 BufferQueue* queue = &queueHandle->queue;
359 return queue->getMaxCount();
363 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
364 if (
nullptr == queueHandle) {
367 BufferQueue* queue = &queueHandle->queue;
368 return queue->getDepth();
372 QueueHandle* queueHandle =
reinterpret_cast<QueueHandle*
>(this->
m_handle);
373 if (
nullptr == queueHandle) {
376 BufferQueue* queue = &queueHandle->queue;
377 return queue->getMsgSize();
PlatformPointerCastType POINTER_CAST
PlatformIntType NATIVE_INT_TYPE
uint8_t U8
8-bit unsigned integer
PlatformUIntType NATIVE_UINT_TYPE
A generic buffer queue data structure.
bool create(NATIVE_UINT_TYPE depth, NATIVE_UINT_TYPE msgSize)
BufferQueue creation.
bool pop(U8 *buffer, NATIVE_UINT_TYPE &size, NATIVE_INT_TYPE &priority)
pop an item off the queue
bool isEmpty()
check if the queue is empty
bool push(const U8 *buffer, NATIVE_UINT_TYPE size, NATIVE_INT_TYPE priority)
push an item onto the queue
bool isFull()
check if the queue is full
pthread_cond_t queueNotEmpty
bool create(NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
pthread_mutex_t queueLock
pthread_cond_t queueNotFull
NATIVE_INT_TYPE getMsgSize() const
get the message size (maximum message size queue can hold)
@ QUEUE_SIZE_MISMATCH
attempted to send or receive with buffer too large, too small
@ QUEUE_UNINITIALIZED
Queue wasn't initialized successfully.
@ QUEUE_NO_MORE_MSGS
If non-blocking, all the messages have been drained.
@ QUEUE_EMPTY_BUFFER
supplied buffer is empty
@ QUEUE_OK
message sent/received okay
@ QUEUE_FULL
queue was full when attempting to send a message
QueueStatus send(const Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE priority, QueueBlocking block)
send a message
QueueStatus createInternal(const Fw::StringBase &name, NATIVE_INT_TYPE depth, NATIVE_INT_TYPE msgSize)
create a message queue
QueueStatus receive(Fw::SerializeBufferBase &buffer, NATIVE_INT_TYPE &priority, QueueBlocking block)
receive a message
NATIVE_INT_TYPE getQueueSize() const
get the queue depth (maximum number of messages queue can hold)
NATIVE_INT_TYPE getMaxMsgs() const
get the maximum number of messages (high watermark)
@ QUEUE_NONBLOCKING
Queue receive always returns even if there is no message.
NATIVE_INT_TYPE getNumMsgs() const
get the number of messages in the queue
POINTER_CAST m_handle
handle for implementation specific queue
Queue::QueueStatus receiveBlock(QueueHandle *queueHandle, U8 *buffer, NATIVE_INT_TYPE capacity, NATIVE_INT_TYPE &actualSize, NATIVE_INT_TYPE &priority)
Queue::QueueStatus sendBlock(QueueHandle *queueHandle, const U8 *buffer, NATIVE_INT_TYPE size, NATIVE_INT_TYPE priority)
Queue::QueueStatus receiveNonBlock(QueueHandle *queueHandle, U8 *buffer, NATIVE_INT_TYPE capacity, NATIVE_INT_TYPE &actualSize, NATIVE_INT_TYPE &priority)
Queue::QueueStatus sendNonBlock(QueueHandle *queueHandle, const U8 *buffer, NATIVE_INT_TYPE size, NATIVE_INT_TYPE priority)