FreeRTOS-rust
FreeRTOS-rust copied to clipboard
`Semaphore::create_binary` can't be used
Quoting the docs:
[...] binary semaphores created using xSemaphoreCreateBinary() are created in a state such that the the semaphore must first be 'given' before it can be 'taken'
The Semaphore API only allows locking, and then dropping the guard, which means there is no way to "give" a binary semaphore. This API also makes using Semaphores as synchronization tools unwieldy.
Good point. PR is welcome. Since I'm not maintaining any active code using this repo there is not much activity from my side, but any help is welcome.
One solution would be to directly implement give
and take
, per the FreeRTOS API, which does not hand back a SemaphoreGuard. lock
, which does, can still exist, too. This would also be "familiar" for people familiar with FreeRTOS.
Even looking at the std::sync::Mutex
, doing a directly unlock
requires unstable features to call drop
directly:
https://doc.rust-lang.org/src/std/sync/mutex.rs.html#337-339
If you really wanted completeness, some properly named version of new_binary
like new_binary_ready
could be implemented to just call the shim function to give it at the time of creation.
This issue seems to have been fixed in #46 in exactly this way:
One solution would be to directly implement
give
andtake
, per the FreeRTOS API, which does not hand back a SemaphoreGuard.
Agree, will close. If anyone feels there's more to do we can re-open.