FreeRTOS-rust icon indicating copy to clipboard operation
FreeRTOS-rust copied to clipboard

`Semaphore::create_binary` can't be used

Open bugadani opened this issue 2 years ago • 1 comments

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.

bugadani avatar Oct 14 '21 14:10 bugadani

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.

niondir avatar Jan 19 '22 21:01 niondir

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.

apullin avatar Sep 26 '22 05:09 apullin

This issue seems to have been fixed in #46 in exactly this way:

One solution would be to directly implement give and take, per the FreeRTOS API, which does not hand back a SemaphoreGuard.

agerasev avatar Jan 03 '23 07:01 agerasev

Agree, will close. If anyone feels there's more to do we can re-open.

schteve avatar Jan 03 '23 17:01 schteve