A simple semaphore
- data BSem
- newBSem :: IO BSem
- newLockedBSem :: IO BSem
- tryAcquireBSems :: [BSem] -> IO (Maybe (IO ()))
- tryAcquireBSemsWithError :: (object -> BSem) -> (object -> IO String) -> [object] -> IO (WithError (IO ()))
- tryAcquireBSemsWithError1 :: (object -> IO BSem) -> (object -> IO (Maybe String)) -> [object] -> IO (WithError (IO ()))
Documentation
newLockedBSem :: IO BSemSource
Create a new locked BSem
tryAcquireBSems :: [BSem] -> IO (Maybe (IO ()))Source
tryAcquireBSems attempts to acquire a list of BSems. If successful it returns the action to release them all again. If unsuccessful it returns Nothing, and leaves all the BSems released.
tryAcquireBSemsWithError :: (object -> BSem) -> (object -> IO String) -> [object] -> IO (WithError (IO ()))Source
tryAcquireBSemsWithError is a generalisation of tryAcquireBSems, which produces an error message
The first argument extracts an object's BSem; the second gets a String to be used as a message if we can't get the object's lock.
tryAcquireBSemsWithError1 :: (object -> IO BSem) -> (object -> IO (Maybe String)) -> [object] -> IO (WithError (IO ()))Source
tryAcquireBSemsWithError1 toBSem getMessIfError objects attempts to acquire the BSems in (map toBSem objects). In the event of a (toBSem object) already being acquired, it looks at the result of getMessIfError object. If this is (Just mess) it returns an error condition with message (mess), first releasing all BSems it has already acquired; if it is (Nothing) it goes on to attempt to acquire the BSems for the remaining objects. If it gets to the end of the list it returns an action which can be used to release all the BSems it has acquired.