]> git.corax.cc Git - toolbox/commit
include/sem: Re-implement semaphores without busy-waiting workaround
authorMatthias Kruk <m@m10k.eu>
Sat, 24 Apr 2021 00:21:44 +0000 (09:21 +0900)
committerMatthias Kruk <m@m10k.eu>
Sat, 24 Apr 2021 00:33:35 +0000 (09:33 +0900)
commite4865d133cc8106cd3d9ec1a381ce579fa522c76
tree80d0c81eeee532721cbed6dac684c07b90bc1898
parent1582417b5d3cc8da595c854961b73fb54cf662a7
include/sem: Re-implement semaphores without busy-waiting workaround

The current sem module has a design issue that requires the use of sleep
or inotifywait to avoid busy-waiting when the semaphore counter is zero.
This commit adds a new sem implementation that avoids the problem
altogether through the use of a separate mutex (called waitlock), which
sem_wait() will attempt to acquire, causing it to be blocked until the
waitlock is released by a call to sem_post().
Further, the new implementation keeps all filesystem objects belonging to
a semaphore in a directory, giving it a cleaner appearance.

This commit also adds several test cases for the new sem module.
include/sem.sh
test/sem.sh [new file with mode: 0755]