Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Freeing critical sections via atexit in system/alloc and system/io #19062

Merged
merged 7 commits into from
Oct 29, 2021
3 changes: 0 additions & 3 deletions lib/std/exitprocs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ proc callClosures() {.noconv.} =
of kClosure: fun.fun1()
of kNoconv: fun.fun2()

when not defined(js) and not defined(nimOwnedEnabled):
deinitLock(gFunsLock)

template fun() =
if gFuns.len == 0:
addAtExit(callClosures)
Expand Down
3 changes: 3 additions & 0 deletions lib/system/alloc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1054,9 +1054,12 @@ template instantiateForRegion(allocator: untyped) {.dirty.} =
it = it.next

when hasThreadSupport:
proc addSysExitProc(quitProc: proc() {.noconv.}) {.importc: "atexit", header: "<stdlib.h>".}

var sharedHeap: MemRegion
var heapLock: SysLock
initSysLock(heapLock)
addSysExitProc(proc() {.noconv.} = deinitSys(heapLock))

proc getFreeMem(): int =
#sysAssert(result == countFreeMem())
Expand Down
8 changes: 4 additions & 4 deletions lib/system/io.nim
Original file line number Diff line number Diff line change
Expand Up @@ -777,15 +777,15 @@ proc setStdIoUnbuffered*() {.tags: [], benign.} =

when declared(stdout):
when defined(windows) and compileOption("threads"):
proc addSysExitProc(quitProc: proc() {.noconv.}) {.importc: "atexit", header: "<stdlib.h>".}

const insideRLocksModule = false
include "system/syslocks"


var echoLock: SysLock
initSysLock echoLock

when not defined(js) and not defined(nimOwnedEnabled):
import std/exitprocs
addExitProc(proc() {.noconv.} = deinitSys echoLock)
addSysExitProc(proc() {.noconv.} = deinitSys(echoLock))

const stdOutLock = not defined(windows) and
not defined(android) and
Expand Down