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.
lock="$1"
while ! mutex_trylock "$lock"; do
- sleep 1
+ inotifywait -qq "${lock%/*}"
done
return 0