Perhaps it'd be more readable to have a type alias for the extensional representation of LockWaiting `(L.LockAllocation a b, S.Set (c, b, [L.LockRequest a]))`.
In any case LGTM (no need to resend if you like the idea). On Wed, Apr 9, 2014 at 9:06 PM, Klaus Aehlig <[email protected]> wrote: > Add a function to obtain some lock waiting structure from a > given extensional representation. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > src/Ganeti/Locking/Waiting.hs | 11 +++++++++++ > 1 file changed, 11 insertions(+) > > diff --git a/src/Ganeti/Locking/Waiting.hs b/src/Ganeti/Locking/Waiting.hs > index d0f60a8..24a4726 100644 > --- a/src/Ganeti/Locking/Waiting.hs > +++ b/src/Ganeti/Locking/Waiting.hs > @@ -34,6 +34,7 @@ module Ganeti.Locking.Waiting > , releaseResources > , getPendingRequests > , extRepr > + , fromExtRepr > ) where > > import Control.Arrow ((&&&)) > @@ -235,3 +236,13 @@ releaseResources owner state = > . M.keys . L.listLocks owner $ getAllocation state' > (state'', (_, notify)) = updateLocks owner request state' > in (state'', notify) > + > +-- | Obtain a LockWaiting from its extensional representation. > +fromExtRepr :: (Lock a, Ord b, Ord c) > + => (L.LockAllocation a b, S.Set (c, b, [L.LockRequest a])) > + -> LockWaiting a b c > +fromExtRepr (alloc, pending) = > + S.foldl (\s (prio, owner, req) -> > + fst $ updateLocksWaiting prio owner req s) > + (emptyWaiting { lwAllocation = alloc }) > + pending > -- > 1.9.1.423.g4596e3a > >
