...allowing to request at least a certain number of the requests to succeed and otherwise not touch the locking state.
Signed-off-by: Klaus Aehlig <[email protected]> Reviewed-by: Hrvoje Ribicic <[email protected]> Cherry-picked from 96245004980fdf9b8f2257a52ada81b08404b75b. Signed-off-by: Klaus Aehlig <[email protected]> --- src/Ganeti/Locking/Waiting.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Ganeti/Locking/Waiting.hs b/src/Ganeti/Locking/Waiting.hs index a16ce88..6e48388 100644 --- a/src/Ganeti/Locking/Waiting.hs +++ b/src/Ganeti/Locking/Waiting.hs @@ -41,6 +41,7 @@ module Ganeti.Locking.Waiting , downGradeLocksPredicate , intersectLocks , opportunisticLockUnion + , guardedOpportunisticLockUnion ) where import Control.Arrow ((&&&), (***), second) @@ -350,3 +351,17 @@ opportunisticLockUnion owner reqs state = s in (s', if result == Ok S.empty then lock:success else success) in second (flip (,) S.empty) $ foldl maybeAllocate (state, []) reqs' + +-- | A guarded version of opportunisticLockUnion; if the number of fulfilled +-- requests is not at least the given amount, then do not change anything. +guardedOpportunisticLockUnion :: (Lock a, Ord b, Ord c) + => Int + -> b + -> [(a, L.OwnerState)] + -> LockWaiting a b c + -> (LockWaiting a b c, ([a], S.Set b)) +guardedOpportunisticLockUnion count owner reqs state = + let (state', (acquired, toNotify)) = opportunisticLockUnion owner reqs state + in if length acquired < count + then (state, ([], S.empty)) + else (state', (acquired, toNotify)) -- 2.0.0.526.g5318336
