]> git.corax.cc Git - toolbox/commit
include/mutex,wmutex: Add weak mutexes that don't enforce ownership
authorMatthias Kruk <m@m10k.eu>
Fri, 23 Apr 2021 22:01:00 +0000 (07:01 +0900)
committerMatthias Kruk <m@m10k.eu>
Fri, 23 Apr 2021 22:25:41 +0000 (07:25 +0900)
commit1582417b5d3cc8da595c854961b73fb54cf662a7
tree0770ee67a6541559e83567a1908fa5403cf10677
parent602532b242b39d085368860d03d1b322aa7061ee
include/mutex,wmutex: Add weak mutexes that don't enforce ownership

When using mutexes as a means for signalling between two processes, the
lock and unlock operation will almost never be executed by the same
process. However, the mutex module does not allow such behavior.
This commit adds the wmutex module (the "w" is for "weak") which does
not enforce ownership on mutexes.

As a side note, the same could have been achieved by adding something
like mutex_weak_lock() and mutex_weak_unlock() to the mutex module, but
that would lead to people mixing the two. Implementing them in separate
modules hopefully makes it more clear that using wmutex functions on a
mutex (and vice-versa) is not acceptable. If necessary, I might even
implement the two in different ways so a mutex can't be released with
wmutex_unlock().
include/mutex.sh
include/wmutex.sh [new file with mode: 0644]
test/mutex.sh
test/wmutex.sh [new file with mode: 0755]