Because sem_trywait() does not unlock the waitlock if the counter is
greater than 1, the next caller will be left waiting until sem_post()
is executed.
This commit changes sem_trywait() to call sem_wait() with a timeout
of 0 seconds, since this issue does not affect sem_wait().
sem_trywait() {
local name="$1"
- local waitlock
- local countlock
- local counter
- local err
-
- waitlock=$(_sem_get_waitlock "$name")
- countlock=$(_sem_get_countlock "$name")
- counter=$(_sem_get_counter "$name")
- err=1
-
- if ! wmutex_trylock "$waitlock"; then
- return 1
- fi
-
- if mutex_lock "$countlock"; then
- _sem_counter_dec "$counter"
- mutex_unlock "$countlock"
- err=0
- fi
-
- return "$err"
+ sem_wait "$name" 0
+ return "$?"
}
sem_post() {