about summary refs log tree commit diff
path: root/Functions/Calendar/calendar_lockfiles
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-03-26 14:33:31 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-03-26 14:33:31 +0000
commit4b7b7f56f1cde7e317fce378d0d0e5c83686ff72 (patch)
tree2420ad49f480b9c2de0c3f13da7bca9f8a415678 /Functions/Calendar/calendar_lockfiles
parent7072c10ae223e24f601b3ee99e89dfcc35397122 (diff)
downloadzsh-4b7b7f56f1cde7e317fce378d0d0e5c83686ff72.tar.gz
zsh-4b7b7f56f1cde7e317fce378d0d0e5c83686ff72.tar.xz
zsh-4b7b7f56f1cde7e317fce378d0d0e5c83686ff72.zip
unposted: more random calendar system fixes and improvements
Diffstat (limited to 'Functions/Calendar/calendar_lockfiles')
-rw-r--r--Functions/Calendar/calendar_lockfiles16
1 files changed, 14 insertions, 2 deletions
diff --git a/Functions/Calendar/calendar_lockfiles b/Functions/Calendar/calendar_lockfiles
index 58ee42114..054b3f74b 100644
--- a/Functions/Calendar/calendar_lockfiles
+++ b/Functions/Calendar/calendar_lockfiles
@@ -3,7 +3,7 @@
 
 local file lockfile msgdone
 # Number of attempts to lock a file.  Probably not worth stylising.
-integer lockattempts=3
+integer lockattempts=3 loadtried
 
 # The lockfile name is not stylised: it has to be a fixed
 # derivative of the main fail.
@@ -18,7 +18,19 @@ for file; do
       msgdone="${lockfile}: waiting to acquire lock"
       zle -M $msgdone
     fi
-    sleep 1
+    if (( ! loadtried )); then
+      zmodload -i zsh/zselect 2>/dev/null
+      (( loadtried = 1 ))
+    fi
+    if zmodload -e zsh/zselect; then
+      # This gives us finer grained timing (100th second).
+      # Randomize the sleep between .1 and 1 second so that
+      # we are much less likely to have multiple instances
+      # retrying at once.
+      zselect -t $(( 10 + RANDOM * 90 / 32768 ))
+    else
+      sleep 1
+    fi
   done
   if [[ -n $msgdone ]]; then
     zle -M ${msgdone//?/ }