From 4b7b7f56f1cde7e317fce378d0d0e5c83686ff72 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Mon, 26 Mar 2007 14:33:31 +0000 Subject: unposted: more random calendar system fixes and improvements --- Functions/Calendar/calendar_lockfiles | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'Functions/Calendar/calendar_lockfiles') 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//?/ } -- cgit 1.4.1