summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/mutex.sh4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/mutex.sh b/src/mutex.sh
index dc23070..ec51a2b 100644
--- a/src/mutex.sh
+++ b/src/mutex.sh
@@ -21,6 +21,7 @@
_mutex_trylock()
{
local mutex="${1}"
+ shift 1
(set -C; printf '%d\n' "${$}" >"${mutex}") 2>/dev/null || return ${?}
return 0
@@ -30,6 +31,7 @@ mutex_timedlock()
{
local mutex="${1}"
local timeout="${2}"
+ shift 2
while ! _mutex_trylock "${mutex}"; do
[ ${timeout} -eq 0 ] && return 1
@@ -43,6 +45,7 @@ mutex_timedlock()
mutex_unlock()
{
local mutex="${1}"
+ shift 1
rm -f -- "${mutex}"
}
@@ -50,6 +53,7 @@ mutex_unlock()
mutex_is_unlockable()
{
local mutex="${1}"
+ shift 1
[ "x$(cat -- "${mutex}" 2>/dev/null)" = "x${$}" ] || return ${?}
return 0