lib/mutex.x
Shared mutable-state coordination.
Primary API
| Function | Summary |
|---|---|
Mutex.cleanup | Ends the owned lifetime when a managed local leaves its block. |
Mutex.free | Destroys an unused, unlocked Mutex and releases its Scope storage. |
Mutex.lock | Locks mutex, waiting until it becomes available. |
Mutex.new | Creates an unlocked Mutex owned by the active Scope. |
Mutex.try_lock | Attempts to lock mutex without waiting. |
Mutex.unlock | Unlocks a Mutex held by the calling thread. |
Mutex
Mutex.cleanup
void Mutex.cleanup(Mutex value)
Ends the owned lifetime when a managed local leaves its block.
Source: lib/mutex.x:22
Mutex.free
void Mutex.free(Mutex mutex)
Destroys an unused, unlocked Mutex and releases its Scope storage.
Native destruction occurs first, so a native failure leaves the allocation
intact. No thread may retain the handle or be waiting on it.
Raises: <bad-state> for NULL, or <io-fail> when native destruction
fails.
Source: lib/mutex.x:129
Mutex.lock
void Mutex.lock(Mutex mutex)
Locks mutex, waiting until it becomes available.
The Mutex is non-recursive; the caller must not already hold it.
Raises: <bad-state> for NULL, or <io-fail> when native locking fails.
Source: lib/mutex.x:96
Mutex.new
Mutex Mutex.new(void)
Creates an unlocked Mutex owned by the active Scope.
Raises: <alloc-fail> when storage cannot be allocated, or <io-fail>
when native mutex initialization fails. An initialization failure releases
the allocated storage.
Source: lib/mutex.x:82
Mutex.try_lock
int Mutex.try_lock(Mutex mutex)
Attempts to lock mutex without waiting.
Returns one when acquired or zero when busy.
Raises: <bad-state> for NULL, or <io-fail> for another native failure.
Source: lib/mutex.x:106
Mutex.unlock
void Mutex.unlock(Mutex mutex)
Unlocks a Mutex held by the calling thread.
Raises: <bad-state> for NULL, or <io-fail> when native unlocking fails.
Source: lib/mutex.x:117
Runtime-internal callables
These callables connect runtime translation units. They are documented for source readers but are not supported as user API.
| Function | Summary |
|---|---|
Mutex.recursive_initialize | Initializes a process-lifetime recursive lock. |
Mutex.recursive_lock | Initializes through once, then locks the recursive mutex. |
Mutex.recursive_unlock | Unlocks the recursive mutex. |
Mutex
Mutex.recursive_initialize
void Mutex.recursive_initialize(pthread_mutex_t *mutex, const char *failure)
Initializes a process-lifetime recursive lock.
On pthread failure, prints failure to native stderr and aborts without
allocating. This boundary can run while Error or Scope is failing.
Source: lib/mutex.x:35
Mutex.recursive_lock
void Mutex.recursive_lock( pthread_mutex_t *mutex, pthread_once_t *once, void (*initialize)(void), const char *failure)
Initializes through once, then locks the recursive mutex.
On pthread failure, prints failure to native stderr and aborts.
Source: lib/mutex.x:49
Mutex.recursive_unlock
void Mutex.recursive_unlock(pthread_mutex_t *mutex, const char *failure)
Unlocks the recursive mutex.
On pthread failure, prints failure to native stderr and aborts.
Source: lib/mutex.x:61
Public types
| Type | Kind | Summary |
|---|---|---|
Mutex | struct | A native mutex allocated in the active Scope without recursive locking. |
Mutex
typedef struct Mutex *Mutex
A native mutex allocated in the active Scope without recursive locking.
Its Scope and handle must outlive every user and waiter. Destroy it only
while unlocked, and do not use the handle or its storage after that.
Source: lib/mutex.x:20
Design notes
Mutex is an opaque native mutex. Its Scope owner must outlive every
thread that can use it, and it may be freed only while unlocked.
Tests and examples
make verify (unittest/test-mutex.x).