LGTM

On Tue, Apr 8, 2014 at 2:02 PM, Klaus Aehlig <[email protected]> wrote:

> Add a function that allows an owner to remove a pending request
> it might have. Besides useful for testing, this will also be
> needed to clean up the resources for dead owners.
>
> Signed-off-by: Klaus Aehlig <[email protected]>
> ---
>  src/Ganeti/Locking/Waiting.hs | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/src/Ganeti/Locking/Waiting.hs b/src/Ganeti/Locking/Waiting.hs
> index bfc3464..4079db2 100644
> --- a/src/Ganeti/Locking/Waiting.hs
> +++ b/src/Ganeti/Locking/Waiting.hs
> @@ -30,6 +30,7 @@ module Ganeti.Locking.Waiting
>   , updateLocksWaiting
>   , getAllocation
>   , getPendingOwners
> + , removePendingRequest
>   ) where
>
>  import qualified Data.Map as M
> @@ -183,3 +184,22 @@ updateLocksWaiting prio owner reqs state =
>                                  , lwPending = pending
>                                  }
>    in (state'', (result, notify))
> +
> +-- | Compute the state of a waiting after an owner gives up
> +-- on his pending request.
> +removePendingRequest :: (Lock a, Ord b, Ord c)
> +                     => b -> LockWaiting a b c -> LockWaiting a b c
> +removePendingRequest owner state =
> +  let pendingOwners = lwPendingOwners state
> +      pending = lwPending state
> +  in case M.lookup owner pendingOwners of
> +    Nothing -> state
> +    Just (blocker, entry) ->
> +      let byBlocker = fromMaybe S.empty . M.lookup blocker $ pending
> +          byBlocker' = S.delete entry byBlocker
> +          pending' = if S.null byBlocker'
> +                       then M.delete blocker pending
> +                       else M.insert blocker byBlocker' pending
> +      in state { lwPendingOwners = M.delete owner pendingOwners
> +               , lwPending = pending'
> +               }
> --
> 1.9.1.423.g4596e3a
>
>

Reply via email to