diff options
author | Anatoly Galiulin <galiulin.anatoly@gmail.com> | 2016-03-25 16:41:48 +0600 |
---|---|---|
committer | Anatoly Galiulin <galiulin.anatoly@gmail.com> | 2016-03-31 16:47:55 +0600 |
commit | ebc02f6dc0dd15f0ec34a8c0f22432ca49c71c5b (patch) | |
tree | c188e05a7e15e7e2d323b6498a0ba2badfc8dc96 /lib | |
parent | d836028fe7b18c93c9a9751f470da387eab09af1 (diff) | |
download | Nim-ebc02f6dc0dd15f0ec34a8c0f22432ca49c71c5b.tar.gz |
Fix ``XDeclaredButNotUsed`` warning when locks or rlocks module is used
Diffstat (limited to 'lib')
-rw-r--r-- | lib/core/locks.nim | 2 | ||||
-rw-r--r-- | lib/core/rlocks.nim | 1 | ||||
-rw-r--r-- | lib/system.nim | 20 | ||||
-rw-r--r-- | lib/system/syslocks.nim | 35 |
4 files changed, 28 insertions, 30 deletions
diff --git a/lib/core/locks.nim b/lib/core/locks.nim index 66e0ab520..068e7133c 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -63,4 +63,4 @@ template withLock*(a: Lock, body: untyped) = try: body finally: - a.release() \ No newline at end of file + a.release() diff --git a/lib/core/rlocks.nim b/lib/core/rlocks.nim index 14f04592b..4710d6cf1 100644 --- a/lib/core/rlocks.nim +++ b/lib/core/rlocks.nim @@ -9,6 +9,7 @@ ## This module contains Nim's support for reentrant locks. +const insideRLocksModule = true include "system/syslocks" type diff --git a/lib/system.nim b/lib/system.nim index fefabe53f..03b9e158a 100644 --- a/lib/system.nim +++ b/lib/system.nim @@ -2561,6 +2561,16 @@ else: if x < 0: -x else: x {.pop.} +proc compiles*(x: expr): bool {.magic: "Compiles", noSideEffect, compileTime.} = + ## Special compile-time procedure that checks whether `x` can be compiled + ## without any semantic error. + ## This can be used to check whether a type supports some operation: + ## + ## .. code-block:: Nim + ## when not compiles(3 + 4): + ## echo "'+' for integers is available" + discard + when not defined(JS): #and not defined(nimscript): {.push stack_trace: off, profiler:off.} @@ -3469,16 +3479,6 @@ when hasAlloc: x[j+i] = item[j] inc(j) -proc compiles*(x: expr): bool {.magic: "Compiles", noSideEffect, compileTime.} = - ## Special compile-time procedure that checks whether `x` can be compiled - ## without any semantic error. - ## This can be used to check whether a type supports some operation: - ## - ## .. code-block:: Nim - ## when not compiles(3 + 4): - ## echo "'+' for integers is available" - discard - when declared(initDebugger): initDebugger() diff --git a/lib/system/syslocks.nim b/lib/system/syslocks.nim index 8afd5d201..07f6fe167 100644 --- a/lib/system/syslocks.nim +++ b/lib/system/syslocks.nim @@ -88,17 +88,16 @@ else: #include <pthread.h>""".} = object SysLockType = distinct cint - proc SysLockType_Reentrant: SysLockType = - {.emit: "`result` = PTHREAD_MUTEX_RECURSIVE;".} - proc initSysLock(L: var SysLock, attr: ptr SysLockAttr = nil) {. importc: "pthread_mutex_init", header: "<pthread.h>", noSideEffect.} - proc initSysLockAttr(a: var SysLockAttr) {. - importc: "pthread_mutexattr_init", header: "<pthread.h>", noSideEffect.} - - proc setSysLockType(a: var SysLockAttr, t: SysLockType) {. - importc: "pthread_mutexattr_settype", header: "<pthread.h>", noSideEffect.} + when compiles(insideRLocksModule): + proc SysLockType_Reentrant: SysLockType = + {.emit: "`result` = PTHREAD_MUTEX_RECURSIVE;".} + proc initSysLockAttr(a: var SysLockAttr) {. + importc: "pthread_mutexattr_init", header: "<pthread.h>", noSideEffect.} + proc setSysLockType(a: var SysLockAttr, t: SysLockType) {. + importc: "pthread_mutexattr_settype", header: "<pthread.h>", noSideEffect.} proc acquireSys(L: var SysLock) {.noSideEffect, importc: "pthread_mutex_lock", header: "<pthread.h>".} @@ -113,14 +112,12 @@ else: proc deinitSys(L: var SysLock) {.noSideEffect, importc: "pthread_mutex_destroy", header: "<pthread.h>".} - proc initSysCond(cond: var SysCond, cond_attr: pointer = nil) {. - importc: "pthread_cond_init", header: "<pthread.h>", noSideEffect.} - proc waitSysCond(cond: var SysCond, lock: var SysLock) {. - importc: "pthread_cond_wait", header: "<pthread.h>", noSideEffect.} - proc signalSysCond(cond: var SysCond) {. - importc: "pthread_cond_signal", header: "<pthread.h>", noSideEffect.} - - proc deinitSysCond(cond: var SysCond) {.noSideEffect, - importc: "pthread_cond_destroy", header: "<pthread.h>".} - -{.pop.} + when not compiles(insideRLocksModule): + proc initSysCond(cond: var SysCond, cond_attr: pointer = nil) {. + importc: "pthread_cond_init", header: "<pthread.h>", noSideEffect.} + proc waitSysCond(cond: var SysCond, lock: var SysLock) {. + importc: "pthread_cond_wait", header: "<pthread.h>", noSideEffect.} + proc signalSysCond(cond: var SysCond) {. + importc: "pthread_cond_signal", header: "<pthread.h>", noSideEffect.} + proc deinitSysCond(cond: var SysCond) {.noSideEffect, + importc: "pthread_cond_destroy", header: "<pthread.h>".} |