Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/pure/asyncdispatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1216,6 +1216,15 @@ else:

var gDisp{.threadvar.}: owned PDispatcher ## Global dispatcher

when defined(nuttx):
import std/exitprocs

proc cleanDispatcher() {.noconv.} =
gDisp = nil

proc addFinalyzer() =
addExitProc(cleanDispatcher)

proc setGlobalDispatcher*(disp: owned PDispatcher) =
if not gDisp.isNil:
assert gDisp.callbacks.len == 0
Expand All @@ -1225,6 +1234,8 @@ else:
proc getGlobalDispatcher*(): PDispatcher =
if gDisp.isNil:
setGlobalDispatcher(newDispatcher())
when defined(nuttx):
addFinalyzer()
result = gDisp

proc getIoHandler*(disp: PDispatcher): Selector[AsyncData] =
Expand Down Expand Up @@ -1591,7 +1602,7 @@ else:
owned(Future[tuple[address: string, client: AsyncFD]]) =
var retFuture = newFuture[tuple[address: string,
client: AsyncFD]]("acceptAddr")
proc cb(sock: AsyncFD): bool =
proc cb(sock: AsyncFD): bool {.gcsafe.} =
result = true
var sockAddress: Sockaddr_storage
var addrLen = sizeof(sockAddress).SockLen
Expand Down
1 change: 1 addition & 0 deletions lib/std/exitprocs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ proc callClosures() {.noconv.} =
case fun.kind
of kClosure: fun.fun1()
of kNoconv: fun.fun2()
gFuns.setLen(0)

template fun() =
if gFuns.len == 0:
Expand Down