Skip to content

Commit

Permalink
fixes refc
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout authored Dec 19, 2023
1 parent bf96c85 commit af36749
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
7 changes: 5 additions & 2 deletions lib/core/locks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion lib/core/rlocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions lib/std/private/syslocks.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ when defined(windows):
header: "<windows.h>".}
## 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: "<windows.h>".}
else:
Expand Down Expand Up @@ -132,7 +132,7 @@ else:
proc initSysLockAux(L: var SysLockObj, attr: ptr SysLockAttr) {.
importc: "pthread_mutex_init", header: "<pthread.h>", 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: "<pthread.h>".}
else:
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -209,7 +209,7 @@ else:
proc initSysCondAux(cond: var SysCondObj, cond_attr: ptr SysCondAttr = nil) {.
importc: "pthread_cond_init", header: "<pthread.h>", 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: "<pthread.h>".}
else:
Expand All @@ -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)
Expand Down

0 comments on commit af36749

Please sign in to comment.