| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
System.Semaphore.Internal
Contents
Description
Platform-independent internal API.
Synopsis
- newtype ClientSemaphore = ClientSemaphore ClientSemaphore
- newtype ServerSemaphore = ServerSemaphore ServerSemaphore
- newtype SemaphoreToken = SemaphoreToken SemaphoreToken
- clientSemaphoreName :: ClientSemaphore -> SemaphoreName
- serverClientSemaphore :: ServerSemaphore -> ClientSemaphore
- waitOnSemaphore :: HasCallStack => ClientSemaphore -> IO SemaphoreToken
- tryWaitOnSemaphore :: HasCallStack => ClientSemaphore -> IO (Maybe SemaphoreToken)
- releaseSemaphoreToken :: HasCallStack => SemaphoreToken -> IO ()
- destroyClientSemaphore :: ClientSemaphore -> IO ()
- destroyServerSemaphore :: ServerSemaphore -> IO ()
- getSemaphoreValue :: ServerSemaphore -> IO Int
- create_sem :: SemaphoreName -> Int -> IO (Either SemaphoreError ServerSemaphore)
- open_sem_raw :: SemaphoreName -> IO (Either SemaphoreError ClientSemaphore)
- get_time_seed :: IO Int
Documentation
newtype ClientSemaphore Source #
A client-side semaphore: the handle a jobclient uses to acquire and release tokens from a semaphore created by a jobserver.
Retrieve the underlying name with clientSemaphoreName.
Constructors
| ClientSemaphore ClientSemaphore |
newtype ServerSemaphore Source #
A server-side semaphore: a ClientSemaphore together with the book-keeping
needed to track resource usage by all clients.
Retrieve the corresponding client semaphore with serverClientSemaphore.
Constructors
| ServerSemaphore ServerSemaphore |
newtype SemaphoreToken Source #
A held semaphore token: evidence of one unit of resource acquired from a semaphore.
Use releaseSemaphoreToken or withSemaphoreToken to ensure prompt release
of semaphore tokens.
Platform-dependent behaviour:
- On POSIX, if all references to a
SemaphoreTokenare dropped without being released, a finalizer returns the token to the semaphore. - On Windows, tokens held by a crashed client are permanently lost.
Constructors
| SemaphoreToken SemaphoreToken |
clientSemaphoreName :: ClientSemaphore -> SemaphoreName Source #
Retrieve the underlying name of a client-side semaphore.
serverClientSemaphore :: ServerSemaphore -> ClientSemaphore Source #
Retrieve the client-side semaphore corresponding to a server-side semaphore.
waitOnSemaphore :: HasCallStack => ClientSemaphore -> IO SemaphoreToken Source #
Acquire a token from the semaphore, blocking until one is available.
The returned SemaphoreToken must be released with releaseSemaphoreToken.
For prompt and predictable release of resources, callers should use
withSemaphoreToken or releaseSemaphoreToken.
This operation is interruptible: it can be cancelled by
throwTo, killThread, etc.
If interrupted, any transiently acquired token is automatically returned.
tryWaitOnSemaphore :: HasCallStack => ClientSemaphore -> IO (Maybe SemaphoreToken) Source #
Try to acquire a token from the semaphore without blocking.
Returns Just token if a token was available, Nothing otherwise.
This is not an interruptible operation, but that should not be a problem: this function is not expected to block for long, as the server is supposed to respond immediately.
releaseSemaphoreToken :: HasCallStack => SemaphoreToken -> IO () Source #
Release a semaphore token, returning it to the pool.
Idempotent: a second call on the same token is a safe no-op.
destroyClientSemaphore :: ClientSemaphore -> IO () Source #
Destroy a client-side semaphore.
This is an idempotent operation: double calls to destroyClientSemaphore
do not cause any problems.
destroyServerSemaphore :: ServerSemaphore -> IO () Source #
Destroy a server-side semaphore.
Idempotent. Not interruptible.
getSemaphoreValue :: ServerSemaphore -> IO Int Source #
Query the current semaphore value (how many tokens it has available).
This is mainly for debugging use, as it is easy to introduce race conditions when nontrivial program logic depends on the value returned by this function.
Internals
create_sem :: SemaphoreName -> Int -> IO (Either SemaphoreError ServerSemaphore) Source #
get_time_seed :: IO Int Source #