From af36749d459eecd21e616acfdd1b9b7207e6f0c1 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 19 Dec 2023 03:28:31 +0000 Subject: [PATCH] fixes refc --- lib/core/locks.nim | 7 +++++-- lib/core/rlocks.nim | 5 ++++- lib/std/private/syslocks.nim | 10 +++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/core/locks.nim b/lib/core/locks.nim index 1172e11364ef3..8748cd0007d26 100644 --- a/lib/core/locks.nim +++ b/lib/core/locks.nim @@ -20,6 +20,9 @@ when not compileOption("threads") and not defined(nimdoc): import std/private/syslocks +const arcLikeMem = defined(gcArc) or defined(gcAtomicArc) or defined(gcOrc) + + type Lock* = SysLock ## Nim lock; whether this is re-entrant ## or not is unspecified! @@ -37,7 +40,7 @@ proc initLock*(lock: var Lock) {.inline.} = when not defined(js): initSysLock(lock) -when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): +when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitLock*(lock {.byref.} : Lock) {.inline.} = ## Frees the resources associated with the lock. deinitSys(lock) @@ -65,7 +68,7 @@ proc initCond*(cond: var Cond) {.inline.} = ## Initializes the given condition variable. initSysCond(cond) -when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): +when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitCond*(cond {.byref.} : Cond) {.inline.} = ## Frees the resources associated with the condition variable. deinitSysCond(cond) diff --git a/lib/core/rlocks.nim b/lib/core/rlocks.nim index 9c4898603635e..8e3acc30abb4f 100644 --- a/lib/core/rlocks.nim +++ b/lib/core/rlocks.nim @@ -21,6 +21,9 @@ import std/private/syslocks type RLock* = SysLock ## Nim lock, re-entrant +const arcLikeMem = defined(gcArc) or defined(gcAtomicArc) or defined(gcOrc) + + proc initRLock*(lock: var RLock) {.inline.} = ## Initializes the given lock. when defined(posix): @@ -32,7 +35,7 @@ proc initRLock*(lock: var RLock) {.inline.} = initSysLock(lock) -when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): +when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitRLock*(lock {.byref.} : RLock) {.inline.} = ## Frees the resources associated with the lock. deinitSys(lock) diff --git a/lib/std/private/syslocks.nim b/lib/std/private/syslocks.nim index af814d08c74f8..3a16630772124 100644 --- a/lib/std/private/syslocks.nim +++ b/lib/std/private/syslocks.nim @@ -46,7 +46,7 @@ when defined(windows): header: "".} ## Releases the lock `L`. - when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): + when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitSys*(L {.byref.} : SysLock) {.importc: "DeleteCriticalSection", header: "".} else: @@ -132,7 +132,7 @@ else: proc initSysLockAux(L: var SysLockObj, attr: ptr SysLockAttr) {. importc: "pthread_mutex_init", header: "", noSideEffect.} - when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): + when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitSysAux(L {.byref.} : SysLockObj) {.noSideEffect, importc: "pthread_mutex_destroy", header: "".} else: @@ -166,7 +166,7 @@ else: initSysLockAux(L[], attr) - when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): + when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitSys*(L {.byref.} : SysLock) = deinitSysAux(L[]) c_free(L) @@ -209,7 +209,7 @@ else: proc initSysCondAux(cond: var SysCondObj, cond_attr: ptr SysCondAttr = nil) {. importc: "pthread_cond_init", header: "", noSideEffect.} - when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): + when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitSysCondAux(cond {.byref.} : SysCondObj) {.noSideEffect, importc: "pthread_cond_destroy", header: "".} else: @@ -228,7 +228,7 @@ else: cond = cast[SysCond](c_malloc(csize_t(sizeof(SysCondObj)))) initSysCondAux(cond[], cond_attr) - when defined(nimPreviewNonVarDestructor) and defined(nimHasByref): + when defined(arcLikeMem) and defined(nimPreviewNonVarDestructor) and defined(nimHasByref): proc deinitSysCond*(cond {.byref.} : SysCond) = deinitSysCondAux(cond[]) c_free(cond)