From f0341979bd419048e78603d440523fdba217afcc Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Fri, 18 Mar 2016 19:06:34 +0000 Subject: Implement a `lock` template in `locks` module. --- lib/core/locks.nim | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'lib/core') diff --git a/lib/core/locks.nim b/lib/core/locks.nim index f1a74876e..443c09fdc 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -54,3 +54,11 @@ 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 lock*(a: Lock, body: stmt) = + a.acquire() + {.locks: [a].}: + try: + body + finally: + a.release() \ No newline at end of file -- cgit 1.4.1-2-gfad0 From 1cc1a7faf46a50c1e7778b6f3d61ac1a5ae932c7 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 23 Mar 2016 12:45:36 +0000 Subject: Rename locks.lock tmplt to withLock and change body to untyped. --- lib/core/locks.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/core') diff --git a/lib/core/locks.nim b/lib/core/locks.nim index 443c09fdc..ba756a863 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -55,7 +55,7 @@ proc signal*(cond: var Cond) {.inline.} = ## sends a signal to the condition variable `cond`. signalSysCond(cond) -template lock*(a: Lock, body: stmt) = +template withLock*(a: Lock, body: untyped) = a.acquire() {.locks: [a].}: try: -- cgit 1.4.1-2-gfad0 From 34401a3639d016de22050ac3703ce0daa78e18e7 Mon Sep 17 00:00:00 2001 From: Dominik Picheta Date: Wed, 23 Mar 2016 12:47:05 +0000 Subject: Documentation for `withLock`. --- lib/core/locks.nim | 2 ++ 1 file changed, 2 insertions(+) (limited to 'lib/core') diff --git a/lib/core/locks.nim b/lib/core/locks.nim index ba756a863..66e0ab520 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -56,6 +56,8 @@ proc signal*(cond: var Cond) {.inline.} = 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: -- cgit 1.4.1-2-gfad0