Skip to content

Commit

Permalink
sim/queue: support uxQueueMessagesWaiting for SysTask state refactor
Browse files Browse the repository at this point in the history
PR InfiniTimeOrg/InfiniTime#2109 refactors the
`SystemTask.h` state machine to prevent `GoingToSleep` race conditions
(and similar state transistions).

In doing so the function `uxQueueMessagesWaiting()` from NRF SDK was
used. Implement this newly used function.
  • Loading branch information
NeroBurner committed Sep 21, 2024
1 parent 5f076b8 commit 9e3a623
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions sim/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,17 @@ BaseType_t xQueueReceive(QueueHandle_t xQueue, void * const pvBuffer, TickType_t
pxQueue->queue.erase(pxQueue->queue.begin());
return true;
}

UBaseType_t uxQueueMessagesWaiting(const QueueHandle_t xQueue)
{
UBaseType_t uxReturn;
SDL_assert(xQueue);
Queue_t* pxQueue = ( Queue_t * ) xQueue;
// taskENTER_CRITICAL();
{
std::lock_guard<std::mutex> guard(pxQueue->mutex);
uxReturn = static_cast<UBaseType_t>(pxQueue->queue.size());
}
// taskEXIT_CRITICAL();
return uxReturn;
}
1 change: 1 addition & 0 deletions sim/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ QueueHandle_t xQueueCreate(const UBaseType_t uxQueueLength, const UBaseType_t ux
BaseType_t xQueueSend(QueueHandle_t xQueue, const void * const pvItemToQueue, TickType_t xTicksToWait);
BaseType_t xQueueSendFromISR(QueueHandle_t xQueue, const void * const pvItemToQueue, BaseType_t *xHigherPriorityTaskWoken);
BaseType_t xQueueReceive(QueueHandle_t xQueue, void * const pvBuffer, TickType_t xTicksToWait );
UBaseType_t uxQueueMessagesWaiting(const QueueHandle_t xQueue);

0 comments on commit 9e3a623

Please sign in to comment.