]> git.corax.cc Git - toolbox/commitdiff
include/mutex: Use inotifywait to improve performance
authorMatthias Kruk <m@m10k.eu>
Thu, 15 Apr 2021 23:46:33 +0000 (08:46 +0900)
committerMatthias Kruk <m@m10k.eu>
Thu, 15 Apr 2021 23:46:33 +0000 (08:46 +0900)
The current mutex implementation uses sleep to periodically check if
the lock can be acquired. This causes a lot of latency for short waits
and a lot of unnecessary sleep/wakeup cycles for long waits.
This commit changes the mutex implementation to use inotifywait
instead of sleep, increasing mutex performance for both short and long
waits.

include/mutex.sh

index 5760cfd1a9f1e6de1b58e36e8263ecd8699609b7..edc4da76405b61903d35254773b3584f37d37833 100644 (file)
@@ -27,7 +27,7 @@ mutex_lock() {
        lock="$1"
 
        while ! mutex_trylock "$lock"; do
-               sleep 1
+               inotifywait -qq "${lock%/*}"
        done
 
        return 0