aboutsummaryrefslogtreecommitdiff
path: root/Utility/LockPool
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2015-10-08 13:40:23 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2015-10-08 13:40:23 -0400
commitdc7576766528bf5b9951b3f355f49a9f8fc1f183 (patch)
treed7c3f68d402a4586c469f6177b47e42bfc0aa8ff /Utility/LockPool
parente2693da16db892d002b2993443bcbe38b6c6efa0 (diff)
add tryLockShared
Diffstat (limited to 'Utility/LockPool')
-rw-r--r--Utility/LockPool/Posix.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/Utility/LockPool/Posix.hs b/Utility/LockPool/Posix.hs
index 506d7b560..82e0c8e5e 100644
--- a/Utility/LockPool/Posix.hs
+++ b/Utility/LockPool/Posix.hs
@@ -9,6 +9,7 @@ module Utility.LockPool.Posix (
LockHandle,
lockShared,
lockExclusive,
+ tryLockShared,
tryLockExclusive,
checkLocked,
getLockStatus,
@@ -35,11 +36,19 @@ lockShared mode file = makeLockHandle
(P.waitTakeLock P.lockPool file LockShared)
(F.lockShared mode file)
+-- Takes an exclusive lock, blocking until the lock is available.
lockExclusive :: Maybe FileMode -> LockFile -> IO LockHandle
lockExclusive mode file = makeLockHandle
(P.waitTakeLock P.lockPool file LockExclusive)
(F.lockExclusive mode file)
+-- Tries to take a shared lock, but does not block.
+tryLockShared :: Maybe FileMode -> LockFile -> IO (Maybe LockHandle)
+tryLockShared mode file = tryMakeLockHandle
+ (P.tryTakeLock P.lockPool file LockShared)
+ (F.tryLockShared mode file)
+
+-- Tries to take an exclusive lock, but does not block.
tryLockExclusive :: Maybe FileMode -> LockFile -> IO (Maybe LockHandle)
tryLockExclusive mode file = tryMakeLockHandle
(P.tryTakeLock P.lockPool file LockExclusive)