From: Matthias Kruk Date: Thu, 15 Apr 2021 23:46:33 +0000 (+0900) Subject: include/mutex: Use inotifywait to improve performance X-Git-Url: https://git.corax.cc/?a=commitdiff_plain;h=b7ae89d8c1147e1ae7d2c176aa7ab902c951102c;p=toolbox include/mutex: Use inotifywait to improve performance 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. --- diff --git a/include/mutex.sh b/include/mutex.sh index 5760cfd..edc4da7 100644 --- a/include/mutex.sh +++ b/include/mutex.sh @@ -27,7 +27,7 @@ mutex_lock() { lock="$1" while ! mutex_trylock "$lock"; do - sleep 1 + inotifywait -qq "${lock%/*}" done return 0