]> git.corax.cc Git - toolbox/commitdiff
include/{mutex,wmutex}: Change mutexes back to the sleep-based approach
authorMatthias Kruk <m@m10k.eu>
Sun, 6 Jun 2021 02:22:43 +0000 (11:22 +0900)
committerMatthias Kruk <m@m10k.eu>
Sun, 6 Jun 2021 02:22:43 +0000 (11:22 +0900)
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.

include/mutex.sh
include/wmutex.sh

index 4efd9055c7d7d495af5c0d4a0be037a23a15c215..0bb71c2808a4475dc2e90b10e4ce51a6033d5406 100644 (file)
@@ -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
index ff732bd9e7e91706eb6f06bcd7e9fb2b4dadeeb1..d4bcf99be8ee5b4effbfc26b7e3695cbb49605f9 100644 (file)
@@ -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