[Pm-utils] [patch commit] [000] POSIXification of pm-utils
Victor Lowther
victor.lowther at gmail.com
Sun Jan 27 18:15:36 PST 2008
On Jan 27, 2008 7:47 PM, Dan Nicholson <dbn.lists at gmail.com> wrote:
> On Jan 27, 2008 12:25 PM, Victor Lowther <victor.lowther at gmail.com> 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
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 017-make-spin-lock-timeout-actually-work.patch
Type: text/x-patch
Size: 280 bytes
Desc: not available
Url : http://lists.freedesktop.org/archives/pm-utils/attachments/20080127/ec7f5b4a/attachment.bin
More information about the Pm-utils
mailing list