This module contains Nimrod's support for locks and condition vars. If the symbol
preventDeadlocks is defined (compiled with
-d:preventDeadlocks) special logic is added to every
acquire,
tryAcquire and
release action that ensures at runtime that no deadlock can occur. This is achieved by forcing a thread to release its locks should it be part of a deadlock. This thread then re-acquires its locks and proceeds.Low level system locks and condition vars.
TLock = TSysLock
-
Nimrod lock; whether this is re-entrant or not is unspecified! However, compilation in preventDeadlocks-mode guarantees re-entrancy.
TCond = TSysCond
-
Nimrod condition variable
FLock = object of TEffect
-
effect that denotes that some lock operation is performed
FAquireLock = object of FLock
-
effect that denotes that some lock is aquired
FReleaseLock = object of FLock
-
effect that denotes that some lock is released
deadlocksPrevented: int
-
counts the number of times a deadlock has been prevented
maxLocksPerThread = 10
-
max number of locks a thread can hold at the same time; this limit is only relevant when compiled with -d:preventDeadlocks.
proc initLock(lock: var TLock) {.inline, raises: [], tags: [].}
-
Initializes the given lock.
proc deinitLock(lock: var TLock) {.inline, raises: [], tags: [].}
-
Frees the resources associated with the lock.
proc tryAcquire(lock: var TLock): bool {.tags: [FAquireLock], raises: [].}
-
Tries to acquire the given lock. Returns true on success.
proc acquire(lock: var TLock) {.tags: [FAquireLock], raises: [].}
-
Acquires the given lock.
proc release(lock: var TLock) {.tags: [FReleaseLock], raises: [].}
-
Releases the given lock.
proc initCond(cond: var TCond) {.inline, raises: [], tags: [].}
-
Initializes the given condition variable.
proc deinitCond(cond: var TCond) {.inline, raises: [], tags: [].}
-
Frees the resources associated with the lock.
proc wait(cond: var TCond; lock: var TLock) {.inline, raises: [], tags: [].}
-
waits on the condition variable cond.
proc signal(cond: var TCond) {.inline, raises: [], tags: [].}
-
sends a signal to the condition variable cond.