The mutex_lock() and wmutex_lock() functions return immediately if
the timeout is set to 0 or is missing. However, to be compatible with
the previous timeout-less implementations, the functions must wait
forever if no timeout was specified.
This commit changes the two functions so they wait forever if the
timeout is 0 or missing.
local lock="$1"
local -i timeout="$2"
+ local -i remaining
+
+ remaining="$timeout"
+
while ! mutex_trylock "$lock"; do
- if (( --timeout < 0 )); then
+ if (( timeout != 0 && --remaining < 0 )); then
return 1
fi
local lock="$1"
local -i timeout="$2"
+ local -i remaining
+
+ remaining="$timeout"
+
while ! wmutex_trylock "$lock"; do
- if (( --timeout < 0 )); then
+ if (( timeout != 0 && --remaining < 0 )); then
return 1
fi