LGTM
On Wed, Apr 9, 2014 at 9:06 PM, Klaus Aehlig <[email protected]> wrote: > ...as pending requests need to be serialized when serializing > lock waiting structures. > > Signed-off-by: Klaus Aehlig <[email protected]> > --- > src/Ganeti/Locking/Allocation.hs | 14 +++++++++++++- > 1 file changed, 13 insertions(+), 1 deletion(-) > > diff --git a/src/Ganeti/Locking/Allocation.hs > b/src/Ganeti/Locking/Allocation.hs > index d8d3c36..8132fe9 100644 > --- a/src/Ganeti/Locking/Allocation.hs > +++ b/src/Ganeti/Locking/Allocation.hs > @@ -44,7 +44,7 @@ module Ganeti.Locking.Allocation > , opportunisticLockUnion > ) where > > -import Control.Applicative (liftA2, (<$>), (<*>)) > +import Control.Applicative (liftA2, (<$>), (<*>), pure) > import Control.Arrow (second, (***)) > import Control.Monad > import Data.Foldable (for_, find) > @@ -156,6 +156,18 @@ data LockRequest a = LockRequest { lockAffected :: a > } > deriving (Eq, Show, Ord) > > +instance J.JSON a => J.JSON (LockRequest a) where > + showJSON (LockRequest a Nothing) = J.showJSON (a, "release") > + showJSON (LockRequest a (Just OwnShared)) = J.showJSON (a, "shared") > + showJSON (LockRequest a (Just OwnExclusive)) = J.showJSON (a, > "exclusive") > + readJSON (J.JSArray [a, J.JSString tp]) = > + case J.fromJSString tp of > + "release" -> LockRequest <$> J.readJSON a <*> pure Nothing > + "shared" -> LockRequest <$> J.readJSON a <*> pure (Just OwnShared) > + "exclusive" -> LockRequest <$> J.readJSON a <*> pure (Just > OwnExclusive) > + _ -> J.Error $ "malformed request type: " ++ J.fromJSString tp > + readJSON x = J.Error $ "malformed lock request: " ++ show x > + > -- | Lock request for an exclusive lock. > requestExclusive :: a -> LockRequest a > requestExclusive lock = LockRequest { lockAffected = lock > -- > 1.9.1.423.g4596e3a > >
