On Jan 27, 2008 7:47 PM, Dan Nicholson <[EMAIL PROTECTED]> wrote:
> On Jan 27, 2008 12:25 PM, Victor Lowther <[EMAIL PROTECTED]> wrote:
> > Adds a generic locking mechanism built around directory creation/removal.
>
> The timeout support in spin_lock doesn't seem like it would work.
>
> +# spin waiting for the lock with optional timeout.
> +# return once we have it, or the timeout has expired
> +spin_lock()
> +{
> +       # $1 = directory to use as the lock directory
> +       # $2 = optional timeout
> +       local elapsed=0
> +       while ! try_lock $1; do
> +               sleep 1;
> +               [ "x$2" != "x" ] && [ $(( $elapsed == $2 )) -ne 0 ] && return 
> 1
> +       done
> +}
>
> $elapsed never seems to be incremented. I also don't believe that you
> want to sleep before checking the timeout. This results in a `sleep 1'
> even if you haven't specified a timeout; i.e., you want to return
> immediately. Personally, I would write it like this (trying not to let
> too much personal style seep in):

You are correct -- I did not test that path, as nothing uses the
timeout functionaloty right now.

> spin_lock()
> {
>   local elapsed=0
>   local timeout=${2:-0}
>
>   while ! try_lock $1; do
>     [ $timeout -le $elapsed ] && return 1
>     elapsed=$(( $elapsed + 1 ))
>     sleep 1
>   done
> }
>
> What do you think?

Patch against my patch series attached.

> --
> Dan
>
diff -U 0 -rNX /home/victor/pm-utils/trunk/diffignore pm-utils.updates/pm/functions working/pm/functions
--- pm-utils.updates/pm/functions	2008-01-27 18:46:00.000000000 -0600
+++ working/pm/functions	2008-01-27 20:12:05.000000000 -0600
@@ -59,0 +60 @@
+		elapsed=$(($elapsed + 1))
_______________________________________________
Pm-utils mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/pm-utils

Reply via email to