{-# LANGUAGE CPP #-}
module System.Semaphore.Internal
( ClientSemaphore(..), ServerSemaphore(..), SemaphoreToken(..)
, clientSemaphoreName, serverClientSemaphore
, waitOnSemaphore, tryWaitOnSemaphore
, releaseSemaphoreToken
, destroyClientSemaphore, destroyServerSemaphore
, getSemaphoreValue
, create_sem, open_sem_raw
, Impl.get_time_seed
) where
import Data.Coerce ( coerce )
import GHC.Stack ( HasCallStack )
import System.Semaphore.Internal.Version
#if defined(wasm32_HOST_ARCH) || defined(javascript_HOST_ARCH)
import qualified System.Semaphore.Internal.Unsupported as Impl
#elif defined(mingw32_HOST_OS)
import qualified System.Semaphore.Internal.Win32 as Impl
#else
import qualified System.Semaphore.Internal.Posix as Impl
#endif
newtype ClientSemaphore = ClientSemaphore Impl.ClientSemaphore
newtype ServerSemaphore = ServerSemaphore Impl.ServerSemaphore
newtype SemaphoreToken = SemaphoreToken Impl.SemaphoreToken
clientSemaphoreName :: ClientSemaphore -> SemaphoreName
clientSemaphoreName :: ClientSemaphore -> SemaphoreName
clientSemaphoreName = (ClientSemaphore -> SemaphoreName)
-> ClientSemaphore -> SemaphoreName
forall a b. Coercible a b => a -> b
coerce ClientSemaphore -> SemaphoreName
Impl.clientSemaphoreName
serverClientSemaphore :: ServerSemaphore -> ClientSemaphore
serverClientSemaphore :: ServerSemaphore -> ClientSemaphore
serverClientSemaphore = (ServerSemaphore -> ClientSemaphore)
-> ServerSemaphore -> ClientSemaphore
forall a b. Coercible a b => a -> b
coerce ServerSemaphore -> ClientSemaphore
Impl.serverClientSemaphore
waitOnSemaphore :: HasCallStack => ClientSemaphore -> IO SemaphoreToken
waitOnSemaphore :: HasCallStack => ClientSemaphore -> IO SemaphoreToken
waitOnSemaphore = (ClientSemaphore -> IO SemaphoreToken)
-> ClientSemaphore -> IO SemaphoreToken
forall a b. Coercible a b => a -> b
coerce HasCallStack => ClientSemaphore -> IO SemaphoreToken
ClientSemaphore -> IO SemaphoreToken
Impl.waitOnSemaphore
tryWaitOnSemaphore :: HasCallStack => ClientSemaphore -> IO (Maybe SemaphoreToken)
tryWaitOnSemaphore :: HasCallStack => ClientSemaphore -> IO (Maybe SemaphoreToken)
tryWaitOnSemaphore = (ClientSemaphore -> IO (Maybe SemaphoreToken))
-> ClientSemaphore -> IO (Maybe SemaphoreToken)
forall a b. Coercible a b => a -> b
coerce HasCallStack => ClientSemaphore -> IO (Maybe SemaphoreToken)
ClientSemaphore -> IO (Maybe SemaphoreToken)
Impl.tryWaitOnSemaphore
releaseSemaphoreToken :: HasCallStack => SemaphoreToken -> IO ()
releaseSemaphoreToken :: HasCallStack => SemaphoreToken -> IO ()
releaseSemaphoreToken = (SemaphoreToken -> IO ()) -> SemaphoreToken -> IO ()
forall a b. Coercible a b => a -> b
coerce HasCallStack => SemaphoreToken -> IO ()
SemaphoreToken -> IO ()
Impl.releaseSemaphoreToken
destroyClientSemaphore :: ClientSemaphore -> IO ()
destroyClientSemaphore :: ClientSemaphore -> IO ()
destroyClientSemaphore = (ClientSemaphore -> IO ()) -> ClientSemaphore -> IO ()
forall a b. Coercible a b => a -> b
coerce ClientSemaphore -> IO ()
Impl.destroyClientSemaphore
destroyServerSemaphore :: ServerSemaphore -> IO ()
destroyServerSemaphore :: ServerSemaphore -> IO ()
destroyServerSemaphore = (ServerSemaphore -> IO ()) -> ServerSemaphore -> IO ()
forall a b. Coercible a b => a -> b
coerce ServerSemaphore -> IO ()
Impl.destroyServerSemaphore
getSemaphoreValue :: ServerSemaphore -> IO Int
getSemaphoreValue :: ServerSemaphore -> IO Int
getSemaphoreValue = (ServerSemaphore -> IO Int) -> ServerSemaphore -> IO Int
forall a b. Coercible a b => a -> b
coerce ServerSemaphore -> IO Int
Impl.getSemaphoreValue
create_sem :: SemaphoreName -> Int -> IO (Either SemaphoreError ServerSemaphore)
create_sem :: SemaphoreName -> Int -> IO (Either SemaphoreError ServerSemaphore)
create_sem = (SemaphoreName
-> Int -> IO (Either SemaphoreError ServerSemaphore))
-> SemaphoreName
-> Int
-> IO (Either SemaphoreError ServerSemaphore)
forall a b. Coercible a b => a -> b
coerce SemaphoreName -> Int -> IO (Either SemaphoreError ServerSemaphore)
Impl.create_sem
open_sem_raw :: SemaphoreName -> IO (Either SemaphoreError ClientSemaphore)
open_sem_raw :: SemaphoreName -> IO (Either SemaphoreError ClientSemaphore)
open_sem_raw = (SemaphoreName -> IO (Either SemaphoreError ClientSemaphore))
-> SemaphoreName -> IO (Either SemaphoreError ClientSemaphore)
forall a b. Coercible a b => a -> b
coerce SemaphoreName -> IO (Either SemaphoreError ClientSemaphore)
Impl.open_sem_raw