mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
asyncdispatch: for NuttX, add destructor to clear global dispatcher. (#21432)
* asyncdispatch: for NuttX, add destructor to clear global dispatcher using atexit(). Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp> * std: exitprocs: remove "when defined(nuttx)" block. Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp> --------- Signed-off-by: Takeyoshi Kikuchi <kikuchi@centurysys.co.jp>
This commit is contained in:
@@ -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
|
||||
@@ -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] =
|
||||
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user