{-# LANGUAGE CPP #-}
{-# LANGUAGE InterruptibleFFI #-}
{-# LANGUAGE NoImplicitPrelude #-}
module GHC.IO.Handle.Lock (
FileLockingNotSupported(..)
, LockMode(..)
, hLock
, hTryLock
, hUnlock
) where
#include "HsBaseConfig.h"
import Data.Functor (void)
import GHC.Base
import GHC.IO.Handle.Lock.Common (LockMode(..), FileLockingNotSupported(..))
import GHC.IO.Handle.Types (Handle)
#if defined(mingw32_HOST_OS)
import GHC.IO.Handle.Lock.Windows
#elif HAVE_OFD_LOCKING
import GHC.IO.Handle.Lock.LinuxOFD
#elif HAVE_FLOCK
import GHC.IO.Handle.Lock.Flock
#else
import GHC.IO.Handle.Lock.NoOp
#endif
hLock :: Handle -> LockMode -> IO ()
hLock :: Handle -> LockMode -> IO ()
hLock Handle
h LockMode
mode = IO Bool -> IO ()
forall (f :: * -> *) a. Functor f => f a -> f ()
void (IO Bool -> IO ()) -> IO Bool -> IO ()
forall a b. (a -> b) -> a -> b
$ Handle -> String -> LockMode -> Bool -> IO Bool
lockImpl Handle
h String
"hLock" LockMode
mode Bool
True
hTryLock :: Handle -> LockMode -> IO Bool
hTryLock :: Handle -> LockMode -> IO Bool
hTryLock Handle
h LockMode
mode = Handle -> String -> LockMode -> Bool -> IO Bool
lockImpl Handle
h String
"hTryLock" LockMode
mode Bool
False
hUnlock :: Handle -> IO ()
hUnlock :: Handle -> IO ()
hUnlock = Handle -> IO ()
unlockImpl