Skip to content

semphr: implement the FreeRTOS recursive mutex API#199

Draft
faisal-shah wants to merge 1 commit into
InfiniTimeOrg:mainfrom
faisal-shah:freertos-recursive-mutex
Draft

semphr: implement the FreeRTOS recursive mutex API#199
faisal-shah wants to merge 1 commit into
InfiniTimeOrg:mainfrom
faisal-shah:freertos-recursive-mutex

Conversation

@faisal-shah

Copy link
Copy Markdown

Companion to InfiniTimeOrg/InfiniTime#2449, which adds a recursive mutex inside Controllers::FS to make littlefs access thread-safe. The firmware's FS.cpp is compiled into both the simulator and littlefs-do, so the FreeRTOS shim needs xSemaphoreCreateRecursiveMutex, xSemaphoreTakeRecursive and xSemaphoreGiveRecursive.

Implementation: a std::recursive_mutex behind the semaphore handle. The timeout argument is ignored; the only firmware caller uses portMAX_DELAY, matching the blocking lock. Handles from xSemaphoreCreateRecursiveMutex must only be used with the *Recursive functions and vice versa, which is the same rule real FreeRTOS imposes.

This change is additive and safe to merge independently: it compiles against current InfiniTime main (the new functions are simply unused until the FS change lands). Verified locally in the same combination InfiniTime's build-simulator CI job uses: this branch built with -DInfiniTime_DIR pointing at InfiniTime main plus the FS mutex patch, both infinisim and littlefs-do link and run.

Merging this first unblocks the build-simulator check on the InfiniTime PR, since that job clones InfiniSim main.

InfiniTime is gaining a recursive mutex inside Controllers::FS to make
littlefs access thread-safe (InfiniTimeOrg/InfiniTime#2449). The
firmware's FS.cpp is compiled into the simulator and littlefs-do, so the
shim needs xSemaphoreCreateRecursiveMutex, xSemaphoreTakeRecursive and
xSemaphoreGiveRecursive.

Backed by std::recursive_mutex. The timeout argument is ignored: the
only firmware caller uses portMAX_DELAY, matching the blocking lock.
Handles from xSemaphoreCreateRecursiveMutex must only be used with the
*Recursive functions and vice versa, the same rule real FreeRTOS
imposes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant