Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sim/semphr.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "semphr.h"
#include <SDL.h>
#include <mutex>
#include <stdexcept>

QueueHandle_t xSemaphoreCreateMutex() {
Expand Down Expand Up @@ -40,3 +41,18 @@ BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore) {
pxQueue->queue.pop_back();
return true;
}

SemaphoreHandle_t xSemaphoreCreateRecursiveMutex() {
// Only ever locked with portMAX_DELAY, so std::recursive_mutex maps directly.
return reinterpret_cast<SemaphoreHandle_t>(new std::recursive_mutex());
}

BaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t xSemaphore, TickType_t /*xTicksToWait*/) {
reinterpret_cast<std::recursive_mutex*>(xSemaphore)->lock();
return true;
}

BaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t xSemaphore) {
reinterpret_cast<std::recursive_mutex*>(xSemaphore)->unlock();
return true;
}
7 changes: 7 additions & 0 deletions sim/semphr.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,10 @@ QueueHandle_t xSemaphoreCreateMutex();

BaseType_t xSemaphoreTake(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
BaseType_t xSemaphoreGive(SemaphoreHandle_t xSemaphore);

// Recursive mutex, as used by FS. Handles from xSemaphoreCreateRecursiveMutex
// must only be passed to the *Recursive functions and vice versa (same rule as
// real FreeRTOS).
SemaphoreHandle_t xSemaphoreCreateRecursiveMutex();
BaseType_t xSemaphoreTakeRecursive(SemaphoreHandle_t xSemaphore, TickType_t xTicksToWait);
BaseType_t xSemaphoreGiveRecursive(SemaphoreHandle_t xSemaphore);