tur/concurrent
stdlib/concurrent.tur
stub concurrency types for linear resource tracking.
Since: Phase LT4
defstruct
linear
MutexGuard
(defstruct MutexGuard :linear [mutex :ptr<void>])
a linear (exactly-once) RAII wrapper for a held mutex lock.
Since: LT4
defn
mutex-guard-lock
(mutex-guard-lock [mutex] :MutexGuard)
lock a mutex and return a MutexGuard RAII token.
Parameters
| mutex | a ptr<void> pointing to a pthread_mutex_t. |
Returns
A MutexGuard holding the locked mutex.
Example
(let [guard (mutex-guard-lock my-mutex)] ...)
Since: LT4
defn
mutex-guard-unlock
(mutex-guard-unlock [guard : MutexGuard] :int)
release the mutex held by a MutexGuard.
Parameters
| guard | a MutexGuard (by value; guard is consumed). |
Returns
0 on success, error code from pthread_mutex_unlock otherwise.
Example
(mutex-guard-unlock guard) ; => 0
Since: LT4
defn
mutex-guard-valid?
(mutex-guard-valid? [guard : MutexGuard] :bool)
return true if the MutexGuard holds a non-NULL mutex.
Parameters
| guard | a MutexGuard value. |
Returns
true if the underlying mutex pointer is non-NULL.
Example
(mutex-guard-valid? guard) ; => true
Since: LT4