-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat(c-bindings): add function to dealloc nodes #2499
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -100,6 +100,21 @@ proc waku_new(configJson: cstring, | |||||||||||||||||||
|
||||||||||||||||||||
return ctx | ||||||||||||||||||||
|
||||||||||||||||||||
proc waku_destroy(ctx: ptr Context, | ||||||||||||||||||||
callback: WakuCallBack, | ||||||||||||||||||||
userData: pointer): cint {.dynlib, exportc.} = | ||||||||||||||||||||
|
||||||||||||||||||||
if isNil(callback): | ||||||||||||||||||||
return RET_MISSING_CALLBACK | ||||||||||||||||||||
|
||||||||||||||||||||
let stopNodeRes = waku_thread.stopWakuNodeThread(ctx) | ||||||||||||||||||||
if stopNodeRes.isErr(): | ||||||||||||||||||||
let msg = $stopNodeRes.error | ||||||||||||||||||||
callback(RET_ERR, unsafeAddr msg[0], cast[csize_t](len(msg)), userData) | ||||||||||||||||||||
return RET_ERR | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The
Suggested change
|
||||||||||||||||||||
|
||||||||||||||||||||
return RET_OK | ||||||||||||||||||||
|
||||||||||||||||||||
proc waku_version(ctx: ptr Context, | ||||||||||||||||||||
callback: WakuCallBack, | ||||||||||||||||||||
userData: pointer): cint {.dynlib, exportc.} = | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -58,7 +58,7 @@ proc run(ctx: ptr Context) {.thread.} = | |||||
var request: ptr InterThreadRequest | ||||||
waitFor ctx.reqSignal.wait() | ||||||
let recvOk = ctx.reqChannel.tryRecv(request) | ||||||
if recvOk == true: | ||||||
if running.load and recvOk == true: | ||||||
richard-ramos marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
let resultResponse = | ||||||
waitFor InterThreadRequest.process(request, addr node) | ||||||
|
||||||
|
@@ -95,12 +95,16 @@ proc createWakuThread*(): Result[ptr Context, string] = | |||||
|
||||||
return ok(ctx) | ||||||
|
||||||
proc stopWakuNodeThread*(ctx: ptr Context) = | ||||||
proc stopWakuNodeThread*(ctx: ptr Context): Result[void, string] = | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Out of the scope of this PR but I just realised it worth keeping consistency with the "start" proc:
Suggested change
|
||||||
running.store(false) | ||||||
let fireRes = ctx.reqSignal.fireSync() | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please let me know if I understood correctly. If we fire the signal, the thread moves from nwaku/library/waku_thread/waku_thread.nim Line 59 in 9ef2ecc
And it will exit the loop in nwaku/library/waku_thread/waku_thread.nim Line 55 in 9ef2ecc
Because of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it should move from
I'm actually not sure if while running.load == true:
## Trying to get a request from the libwaku main thread
var request: ptr InterThreadRequest
waitFor ctx.reqSignal.wait()
if not running.load: break <------------------------------
let recvOk = ctx.reqChannel.tryRecv(request)
if recvOk == true:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation! I personally like that alternative better :) Find it more predictable and easier to understand |
||||||
if fireRes.isErr(): | ||||||
return err(fireRes.error) | ||||||
richard-ramos marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
joinThread(ctx.thread) | ||||||
discard ctx.reqSignal.close() | ||||||
discard ctx.respSignal.close() | ||||||
freeShared(ctx) | ||||||
ok() | ||||||
richard-ramos marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
|
||||||
proc sendRequestToWakuThread*(ctx: ptr Context, | ||||||
reqType: RequestType, | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it the lib user responsibility to call this?
Is there a chance to add an exit handler that can automatically do it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Bindings in other languages can automate the call to this function to be executed on some destructor function if available.
Do you have an example of the exit handler idea? I'm not sure how to implement this, so look at something i could use as a guide.