[input-output-hk/cardano-sl] CDEC-494: Prepare for consolidation of blund files into epoch files (#3440)

erikd commented on this pull request.

> @@ -43,3 +44,13 @@ withRead l = bracket_ (acquireRead l) (releaseRead l)
— | Allows to perform action under exclusive lock on ‘RWLock’.
withWrite :: (MonadIO m, MonadMask m) => RWLock -> m a -> m a
withWrite l = bracket_ (acquireWrite l) (releaseWrite l)
+
+— | If the write lock can be acquired, perform the requested action
+— and then release the lock. If the lock cannot be acquired, no
+— action is performed.
+whenAcquireWrite :: (MonadIO m, MonadMask m) => RWLock -> m a -> m (Maybe a)
+whenAcquireWrite l action =
+ bracket
+ (liftIO $ RWL.tryAcquireWrite l)
+ (\ haveLock -> when haveLock $ releaseWrite l)
+ (\ haveLock -> if haveLock then Just <$> action else pure Nothing)

Fixed!