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:
parent
83e3320725
commit
dd629c8f45
2 changed files with 13 additions and 1 deletions
|
|
@ -1216,6 +1216,15 @@ else:
|
||||||
|
|
||||||
var gDisp{.threadvar.}: owned PDispatcher ## Global dispatcher
|
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) =
|
proc setGlobalDispatcher*(disp: owned PDispatcher) =
|
||||||
if not gDisp.isNil:
|
if not gDisp.isNil:
|
||||||
assert gDisp.callbacks.len == 0
|
assert gDisp.callbacks.len == 0
|
||||||
|
|
@ -1225,6 +1234,8 @@ else:
|
||||||
proc getGlobalDispatcher*(): PDispatcher =
|
proc getGlobalDispatcher*(): PDispatcher =
|
||||||
if gDisp.isNil:
|
if gDisp.isNil:
|
||||||
setGlobalDispatcher(newDispatcher())
|
setGlobalDispatcher(newDispatcher())
|
||||||
|
when defined(nuttx):
|
||||||
|
addFinalyzer()
|
||||||
result = gDisp
|
result = gDisp
|
||||||
|
|
||||||
proc getIoHandler*(disp: PDispatcher): Selector[AsyncData] =
|
proc getIoHandler*(disp: PDispatcher): Selector[AsyncData] =
|
||||||
|
|
@ -1591,7 +1602,7 @@ else:
|
||||||
owned(Future[tuple[address: string, client: AsyncFD]]) =
|
owned(Future[tuple[address: string, client: AsyncFD]]) =
|
||||||
var retFuture = newFuture[tuple[address: string,
|
var retFuture = newFuture[tuple[address: string,
|
||||||
client: AsyncFD]]("acceptAddr")
|
client: AsyncFD]]("acceptAddr")
|
||||||
proc cb(sock: AsyncFD): bool =
|
proc cb(sock: AsyncFD): bool {.gcsafe.} =
|
||||||
result = true
|
result = true
|
||||||
var sockAddress: Sockaddr_storage
|
var sockAddress: Sockaddr_storage
|
||||||
var addrLen = sizeof(sockAddress).SockLen
|
var addrLen = sizeof(sockAddress).SockLen
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,7 @@ proc callClosures() {.noconv.} =
|
||||||
case fun.kind
|
case fun.kind
|
||||||
of kClosure: fun.fun1()
|
of kClosure: fun.fun1()
|
||||||
of kNoconv: fun.fun2()
|
of kNoconv: fun.fun2()
|
||||||
|
gFuns.setLen(0)
|
||||||
|
|
||||||
template fun() =
|
template fun() =
|
||||||
if gFuns.len == 0:
|
if gFuns.len == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue