Revision 1243b689

b/src/Ganeti/Locking/Allocation.hs
36 36
  , updateLocks
37 37
  , freeLocks
38 38
  , freeLocksPredicate
39
  , downGradePredicate
39 40
  , intersectLocks
40 41
  , opportunisticLockUnion
41 42
  ) where
......
293 294
      state'' = foldl (updateIndirects owner) state' reqs
294 295
  return (if S.null blocked then state'' else state, blocked)
295 296

  
297
-- | Manipluate all locks of the owner with a given property.
298
manipulateLocksPredicate :: (Lock a, Ord b)
299
                         => (a -> LockRequest a)
300
                         -> (a -> Bool)
301
                         -> b -> LockAllocation a b -> LockAllocation a b
302
manipulateLocksPredicate req prop owner state =
303
  fst . flip (updateLocks owner) state . map req
304
    . filter prop
305
    . M.keys
306
    $ listLocks owner state
307

  
296 308
-- | Compute the state after an owner releases all its locks that
297 309
-- satisfy a certain property.
298 310
freeLocksPredicate :: (Lock a, Ord b)
299 311
                   => (a -> Bool)
300 312
                   -> LockAllocation a b -> b -> LockAllocation a b
301
freeLocksPredicate property state owner =
302
  fst . flip (updateLocks owner) state . map requestRelease
303
    . filter property
304
    . M.keys
305
    $ listLocks owner state
313
freeLocksPredicate prop = flip $ manipulateLocksPredicate requestRelease prop
306 314

  
307 315
-- | Compute the state after an onwer releases all its locks.
308 316
freeLocks :: (Lock a, Ord b) => LockAllocation a b -> b -> LockAllocation a b
309 317
freeLocks = freeLocksPredicate (const True)
310 318

  
319
-- | Downgrade to shared all locks held that satisfy a given predicate.
320
downGradePredicate :: (Lock a, Ord b)
321
                   => (a -> Bool)
322
                   -> b -> LockAllocation a b -> LockAllocation a b
323
downGradePredicate = manipulateLocksPredicate requestShared
324

  
311 325
-- | Restrict the locks of a user to a given set.
312 326
intersectLocks :: (Lock a, Ord b) => b -> [a]
313 327
               -> LockAllocation a b -> LockAllocation a b

Also available in: Unified diff