Merge pull request #3981 from nim-lang/locks-lock-template
Implement a `lock` template in `locks` module.
This commit is contained in:
commit
418985d3f0
1 changed files with 10 additions and 0 deletions
|
|
@ -54,3 +54,13 @@ proc wait*(cond: var Cond, lock: var Lock) {.inline.} =
|
||||||
proc signal*(cond: var Cond) {.inline.} =
|
proc signal*(cond: var Cond) {.inline.} =
|
||||||
## sends a signal to the condition variable `cond`.
|
## sends a signal to the condition variable `cond`.
|
||||||
signalSysCond(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()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue