Because of a bug in the timeout handling, the mutex_lock(),
wmutex_lock(), queue_get(), and sem_wait() functions wait forever if a
positive timeout is specified.
This commit changes the behavior so that the functions will wait
forever if the timeout is -1 or omitted, return immediately if the
timeout is zero, or otherwise wait for the specified number of seconds.
local lock="$1"
local -i timeout="$2"
- local -i remaining
-
- remaining="$timeout"
+ if (( $# < 2 )); then
+ timeout=-1
+ fi
while ! mutex_trylock "$lock"; do
- if (( timeout != 0 && --remaining < 0 )); then
+ if (( timeout-- == 0 )); then
return 1
fi
local item
local err
+ if (( $# < 2 )); then
+ timeout=-1
+ fi
+
sem=$(_queue_get_sem "$queue")
mutex=$(_queue_get_mutex "$queue")
data=$(_queue_get_data "$queue")
local counter
local err
+ if (( $# < 2 )); then
+ timeout=-1
+ fi
+
waitlock=$(_sem_get_waitlock "$name")
countlock=$(_sem_get_countlock "$name")
counter=$(_sem_get_counter "$name")
local lock="$1"
local -i timeout="$2"
- local -i remaining
-
- remaining="$timeout"
+ if (( $# < 2 )); then
+ timeout=-1
+ fi
while ! wmutex_trylock "$lock"; do
- if (( timeout != 0 && --remaining < 0 )); then
+ if (( timeout-- == 0 )); then
return 1
fi