@@ -8,7 +8,7 @@ import System
9||| Send a message of any type to the thread with the given thread id
9||| Send a message of any type to the thread with the given thread id
10||| Returns channel ID if the message was sent successfully, 0 otherwise
10||| Returns channel ID if the message was sent successfully, 0 otherwise
12||| @channel an ID of a specific channel to send the message on. If 0,
12||| @channel an ID of a specific channel to send the message on. If 0,
13||| the receiver will create a new channel ID
13||| the receiver will create a new channel ID
14sendToThread : (thread_id : Ptr) -> (channel : Int) -> a -> IO Int
14sendToThread : (thread_id : Ptr) -> (channel : Int) -> a -> IO Int
@@ -29,7 +29,7 @@ checkMsgs = do me <- getMyVM
29checkMsgsTimeout : Int -> IO Bool
29checkMsgsTimeout : Int -> IO Bool
30checkMsgsTimeout timeout
30checkMsgsTimeout timeout
31 = do me <- getMyVM
31 = do me <- getMyVM
32− msgs <- foreign FFI_C "idris_checkMessagesTimeout"
32+ msgs <- foreign FFI_C "idris_checkMessagesTimeout"
33 (Ptr -> Int -> IO Ptr) me timeout
33 (Ptr -> Int -> IO Ptr) me timeout
34 null <- nullPtr msgs
34 null <- nullPtr msgs
35 pure (not null)
35 pure (not null)
@@ -43,7 +43,7 @@ channel_id : Ptr -> IO Int
43channel_id msg = foreign FFI_C "idris_getChannel" (Ptr -> IO Int) msg
43channel_id msg = foreign FFI_C "idris_getChannel" (Ptr -> IO Int) msg
45||| Check for messages initiating a conversation in the process inbox.
45||| Check for messages initiating a conversation in the process inbox.
46−||| Returns either 'Nothing', if none, or 'Just (pid, channel)' as pid
46+||| Returns either 'Nothing', if none, or 'Just (pid, channel)' as pid
47||| of sender and new channel id.
47||| of sender and new channel id.
48listenMsgs : IO (Maybe (Ptr, Int))
48listenMsgs : IO (Maybe (Ptr, Int))
49listenMsgs = do me <- getMyVM
49listenMsgs = do me <- getMyVM
@@ -58,7 +58,7 @@ listenMsgs = do me <- getMyVM
58||| Check for messages from a specific sender/channel in the process inbox
58||| Check for messages from a specific sender/channel in the process inbox
59||| If channel is '0', accept on any channel.
59||| If channel is '0', accept on any channel.
60checkMsgsFrom : Ptr -> (channel : Int) -> IO Bool
60checkMsgsFrom : Ptr -> (channel : Int) -> IO Bool
61−checkMsgsFrom sender channel
61+checkMsgsFrom sender channel
62 = do me <- getMyVM
62 = do me <- getMyVM
63 msgs <- foreign FFI_C "idris_checkMessagesFrom" (Ptr -> Int -> Ptr -> IO Ptr)
63 msgs <- foreign FFI_C "idris_checkMessagesFrom" (Ptr -> Int -> Ptr -> IO Ptr)
64 me channel sender
64 me channel sender
@@ -73,6 +73,7 @@ getMsg : IO a
73getMsg {a} = do me <- getMyVM
73getMsg {a} = do me <- getMyVM
74 m <- foreign FFI_C "idris_recvMessage" (Ptr -> IO Ptr) me
74 m <- foreign FFI_C "idris_recvMessage" (Ptr -> IO Ptr) me
75 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
75 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
76+ foreign FFI_C "idris_freeMsg" (Ptr -> IO ()) m
78||| Check inbox for messages. If there are none, blocks until a message
79||| Check inbox for messages. If there are none, blocks until a message
@@ -80,9 +81,9 @@ getMsg {a} = do me <- getMyVM
80||| Note that this is not at all type safe! It is intended to be used in
81||| Note that this is not at all type safe! It is intended to be used in
81||| a type safe wrapper.
82||| a type safe wrapper.
82getMsgWithSender : IO (Ptr, Int, a)
83getMsgWithSender : IO (Ptr, Int, a)
83−getMsgWithSender {a}
84+getMsgWithSender {a}
84 = do me <- getMyVM
85 = do me <- getMyVM
85− m <- foreign FFI_C "idris_recvMessage"
86+ m <- foreign FFI_C "idris_recvMessage"
86 (Ptr -> IO Ptr) me
87 (Ptr -> IO Ptr) me
87 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
88 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
88 vm <- sender m
89 vm <- sender m
@@ -94,12 +95,12 @@ getMsgWithSender {a}
94||| blocks until a message arrives. Returns `Nothing` if the sender isn't
95||| blocks until a message arrives. Returns `Nothing` if the sender isn't
96getMsgFrom : Ptr -> (channel : Int) -> IO (Maybe a)
97getMsgFrom : Ptr -> (channel : Int) -> IO (Maybe a)
97−getMsgFrom {a} sender channel
98+getMsgFrom {a} sender channel
98 = do me <- getMyVM
99 = do me <- getMyVM
99 m <- foreign FFI_C "idris_recvMessageFrom"
100 m <- foreign FFI_C "idris_recvMessageFrom"
100 (Ptr -> Int -> Ptr -> IO Ptr) me channel sender
101 (Ptr -> Int -> Ptr -> IO Ptr) me channel sender
101 null <- nullPtr m
102 null <- nullPtr m
102− if null
103+ if null
103 then pure Nothing
104 then pure Nothing
105 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
106 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
@@ -110,5 +111,3 @@ stopThread : IO a
110stopThread = do vm <- getMyVM
111stopThread = do vm <- getMyVM
111 MkRaw res <- foreign FFI_C "idris_stopThread" (Ptr -> IO (Raw a)) vm
112 MkRaw res <- foreign FFI_C "idris_stopThread" (Ptr -> IO (Raw a)) vm