tur/concurrent
stub concurrency types for linear resource tracking.
Defines MutexGuard as a move-only struct wrapping a pthread_mutex_t pointer.
Since: Phase LT4
MutexGuard
(defstruct MutexGuard :linear [mutex :ptr<void>])
a linear (exactly-once) RAII wrapper for a held mutex lock.
Holding a MutexGuard means the mutex is currently locked by this thread. Marking the struct :linear (CK_LINEAR) prevents both silent copies (which would create a phantom lock holder) and silent drops (which would leak the lock). Every MutexGuard must be explicitly consumed via mutex-guard-unlock.
Since: LT4
mutex-guard-lock
(mutex-guard-lock [mutex] :MutexGuard)
lock a mutex and return a MutexGuard RAII token.
| mutex | a ptr<void> pointing to a pthread_mutex_t. |
A MutexGuard holding the locked mutex.
(let [guard (mutex-guard-lock my-mutex)] ...)
Since: LT4
mutex-guard-unlock
(mutex-guard-unlock [guard :MutexGuard] :int)
release the mutex held by a MutexGuard.
| guard | a MutexGuard (by value; guard is consumed). |
0 on success, error code from pthread_mutex_unlock otherwise.
(mutex-guard-unlock guard) ; => 0
Since: LT4
mutex-guard-valid?
(mutex-guard-valid? [guard :MutexGuard] :bool)
return true if the MutexGuard holds a non-NULL mutex.
| guard | a MutexGuard value. |
true if the underlying mutex pointer is non-NULL.
(mutex-guard-valid? guard) ; => true
Since: LT4