-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Thread-safe comms between main thread & Waku Thread - ChannelSPSCSingle
- Loading branch information
1 parent
68e8d9a
commit ae48b46
Showing
10 changed files
with
231 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 0 additions & 21 deletions
21
library/waku_thread/inter_thread_communication/request.nim
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
library/waku_thread/inter_thread_communication/waku_thread_request.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
|
||
## This file contains the base message request type that will be handled. | ||
## The requests are created by the main thread and processed by | ||
## the Waku Thread. | ||
|
||
import | ||
std/json, | ||
stew/results | ||
import | ||
chronos | ||
import | ||
../../../waku/node/waku_node, | ||
./requests/node_lifecycle_request, | ||
./requests/peer_manager_request, | ||
./requests/protocols/relay_request | ||
|
||
type | ||
RequestType* {.pure.} = enum | ||
LIFECYCLE, | ||
PEER_MANAGER, | ||
RELAY, | ||
|
||
type | ||
InterThreadRequest* = object | ||
reqType: RequestType | ||
reqContent: pointer | ||
|
||
proc new*(T: type InterThreadRequest, | ||
reqType: RequestType, | ||
reqContent: pointer): ptr InterThreadRequest = | ||
var ret = cast[ptr InterThreadRequest]( | ||
allocShared0(sizeof(InterThreadRequest))) | ||
ret[].reqType = reqType | ||
ret[].reqContent = reqContent | ||
return ret | ||
|
||
proc process*(T: type InterThreadRequest, | ||
request: ptr InterThreadRequest, | ||
node: ptr WakuNode): | ||
Result[string, string] = | ||
## Processes the request and deallocates its memory | ||
defer: deallocShared(request) | ||
|
||
echo "Request received: " & $request[].reqType | ||
|
||
case request[].reqType | ||
of LIFECYCLE: | ||
waitFor cast[ptr NodeLifecycleRequest](request[].reqContent).process(node) | ||
of PEER_MANAGER: | ||
waitFor cast[ptr PeerManagementRequest](request[].reqContent).process(node) | ||
of RELAY: | ||
waitFor cast[ptr RelayRequest](request[].reqContent).process(node) | ||
|
||
proc `$`*(self: InterThreadRequest): string = | ||
return $self.reqType |
Oops, something went wrong.