tur/mutex
stdlib/mutex.tur
POSIX mutex (pthread_mutex_t) wrapped as ptr<void>.
Since: Phase T19-C
defopaque
linear
Mutex
(Mutex)
defn
mutex-new
(mutex-new :)
allocate and initialise a new POSIX mutex.
Returns
A Mutex handle to a heap-allocated pthread_mutex_t.
Example
(let [m (mutex-new)] ...) ; => Mutex
Since: Phase T19-C
defn
mutex-lock
(mutex-lock [^borrow m : Mutex] :)
acquire the mutex, blocking until it is available.
Parameters
| m | mutex handle returned by mutex-new |
Example
(mutex-lock m)
Since: Phase T19-C
defn
mutex-unlock
(mutex-unlock [^borrow m : Mutex] :)
release the mutex.
Parameters
| m | mutex handle returned by mutex-new |
Example
(mutex-unlock m)
Since: Phase T19-C
defn
mutex-try-lock
(mutex-try-lock [^borrow m : Mutex] :)
attempt to acquire the mutex without blocking.
Parameters
| m | mutex handle returned by mutex-new |
Returns
true if the mutex was successfully acquired; false if it was already held.
Example
(if (mutex-try-lock m) ...) ; => bool
Since: Phase T19-C
defn
mutex-free
(mutex-free [m : Mutex] :)
destroy the mutex and release its memory.
Parameters
| m | mutex handle returned by mutex-new |
Example
(mutex-free m)
Since: Phase T19-C