mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-14 23:33:28 +00:00
Merge pull request #3981 from nim-lang/locks-lock-template
Implement a `lock` template in `locks` module.
This commit is contained in:
@@ -54,3 +54,13 @@ proc wait*(cond: var Cond, lock: var Lock) {.inline.} =
|
||||
proc signal*(cond: var Cond) {.inline.} =
|
||||
## sends a signal to the condition variable `cond`.
|
||||
signalSysCond(cond)
|
||||
|
||||
template withLock*(a: Lock, body: untyped) =
|
||||
## Acquires the given lock, executes the statements in body and
|
||||
## releases the lock after the statements finish executing.
|
||||
a.acquire()
|
||||
{.locks: [a].}:
|
||||
try:
|
||||
body
|
||||
finally:
|
||||
a.release()
|
||||
Reference in New Issue
Block a user