Merge pull request #3981 from nim-lang/locks-lock-template

Implement a `lock` template in `locks` module.
This commit is contained in:
Dominik Picheta
2016-03-23 12:48:38 +00:00

View File

@@ -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()