From: Matthias Kruk Date: Sun, 6 Jun 2021 02:22:43 +0000 (+0900) Subject: include/{mutex,wmutex}: Change mutexes back to the sleep-based approach X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=005ec83231e9ce90fd601fa34ac2585d13b008fd;p=toolbox include/{mutex,wmutex}: Change mutexes back to the sleep-based approach Using inotifywait to wait on a mutex does not work reliably when the mutex is on an NFS and the processes synchronizing on it are running on different machines. This commit changes the implementations of mutex and wmutex back to use sleep instead of inotifywait. --- diff --git a/include/mutex.sh b/include/mutex.sh index 4efd905..0bb71c2 100644 --- a/include/mutex.sh +++ b/include/mutex.sh @@ -24,14 +24,11 @@ mutex_lock() { local -i timeout="$2" while ! mutex_trylock "$lock"; do - # We can't inotifywait on symlinks. Which is - # fine because when the symlink is removed, the - # containing directory is changed. Hence, we can - # watch the containing directory instead. - - if ! inotifywait -qq "${lock%/*}" -t "$timeout"; then + if (( --timeout < 0 )); then return 1 fi + + sleep 1 done return 0 diff --git a/include/wmutex.sh b/include/wmutex.sh index ff732bd..d4bcf99 100644 --- a/include/wmutex.sh +++ b/include/wmutex.sh @@ -24,9 +24,11 @@ wmutex_lock() { local -i timeout="$2" while ! wmutex_trylock "$lock"; do - if ! inotifywait -qq "${lock%/*}" -t "$timeout"; then + if (( --timeout < 0 )); then return 1 fi + + sleep 1 done return 0