[riot-notifications] [RIOT-OS/RIOT] sys/sema_inv: add inverse Semaphore (#15762)
notifications at github.com
Wed Jan 13 17:55:52 CET 2021
### Contribution description
It is often desiderable to sync on multiple threads, e.g. there can be a controller thread that waits for `n` worker threads to finish their job.
An inverse semaphore provides an easy primitive to implement this pattern.
After being initialized with a value `n` (in counter mode), a call to `sema_inv_wait()` will block until each of the `n` threads has called `sema_inv_post()` exactly once.
There are situations where workers might post an event more than once (unless additional state is introduced).
For this case, the alternative mask mode is provided. Here the inverse semaphore is initialized with a bit mask, each worker can clear one or multiple bits with `sema_inv_post_mask()`. A worker can clear it's bit multiple times.
### Testing procedure
A basic test application is provided as `tests/sys_sema_inv`
### Issues/PRs references
Examples: Fixes #1234. See also #5678. Depends on PR #9876.
Please use keywords (e.g., fixes, resolve) with the links to the issues you
resolved, this way they will be automatically closed when your pull request
is merged. See https://help.github.com/articles/closing-issues-using-keywords/.
You can view, comment on, or merge this pull request online at:
-- Commit Summary --
* sys/sema_inv: add inverse Semaphore
* tests/sys_sema_inv: add test for inverse semaphore
-- File Changes --
M sys/Makefile (3)
M sys/Makefile.dep (4)
A sys/include/sema_inv.h (145)
A sys/sema_inv/Makefile (1)
A sys/sema_inv/sema_inv.c (41)
A tests/sys_sema_inv/Makefile (6)
A tests/sys_sema_inv/Makefile.ci (7)
A tests/sys_sema_inv/main.c (127)
A tests/sys_sema_inv/tests/01-run.py (26)
-- Patch Links --
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the notifications