@@ -13,13 +13,14 @@ import System
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
15sendToThread {a} dest channel val
15sendToThread {a} dest channel val
16− = foreign FFI_C "idris_sendMessage" (Ptr -> Int -> Ptr -> Raw a -> IO Int)
17+ foreign FFI_C "idris_sendMessage" (Ptr -> Int -> Ptr -> Raw a -> IO Int)
17− prim__vm channel dest (MkRaw val)
18+ me channel dest (MkRaw val)
19||| Check for messages in the process inbox
20||| Check for messages in the process inbox
20checkMsgs : IO Bool
21checkMsgs : IO Bool
22+checkMsgs = do me <- getMyVM
21−checkMsgs = do msgs <- foreign FFI_C "idris_checkMessages" (Ptr -> IO Ptr)
23+ msgs <- foreign FFI_C "idris_checkMessages" (Ptr -> IO Ptr) me
23 null <- nullPtr msgs
24 null <- nullPtr msgs
24 pure (not null)
25 pure (not null)
@@ -27,8 +28,9 @@ checkMsgs = do msgs <- foreign FFI_C "idris_checkMessages" (Ptr -> IO Ptr)
27||| If no messages, waits for the given number of seconds
28||| If no messages, waits for the given number of seconds
28checkMsgsTimeout : Int -> IO Bool
29checkMsgsTimeout : Int -> IO Bool
29checkMsgsTimeout timeout
30checkMsgsTimeout timeout
30− = do msgs <- foreign FFI_C "idris_checkMessagesTimeout"
32+ msgs <- foreign FFI_C "idris_checkMessagesTimeout"
31− (Ptr -> Int -> IO Ptr) prim__vm timeout
33+ (Ptr -> Int -> IO Ptr) me timeout
32 null <- nullPtr msgs
34 null <- nullPtr msgs
33 pure (not null)
35 pure (not null)
@@ -44,8 +46,9 @@ channel_id msg = foreign FFI_C "idris_getChannel" (Ptr -> IO Int) msg
44||| Returns either 'Nothing', if none, or 'Just (pid, channel)' as pid
46||| Returns either 'Nothing', if none, or 'Just (pid, channel)' as pid
45||| of sender and new channel id.
47||| of sender and new channel id.
46listenMsgs : IO (Maybe (Ptr, Int))
48listenMsgs : IO (Maybe (Ptr, Int))
49+listenMsgs = do me <- getMyVM
47−listenMsgs = do msg <- foreign FFI_C "idris_checkInitMessages" (Ptr -> IO Ptr)
50+ msg <- foreign FFI_C "idris_checkInitMessages" (Ptr -> IO Ptr)
49 null <- nullPtr msg
52 null <- nullPtr msg
50 if null then pure Nothing
53 if null then pure Nothing
51 else do s_id <- sender msg
54 else do s_id <- sender msg
@@ -56,8 +59,9 @@ listenMsgs = do msg <- foreign FFI_C "idris_checkInitMessages" (Ptr -> IO Ptr)
56||| If channel is '0', accept on any channel.
59||| If channel is '0', accept on any channel.
57checkMsgsFrom : Ptr -> (channel : Int) -> IO Bool
60checkMsgsFrom : Ptr -> (channel : Int) -> IO Bool
58checkMsgsFrom sender channel
61checkMsgsFrom sender channel
59− = do msgs <- foreign FFI_C "idris_checkMessagesFrom" (Ptr -> Int -> Ptr -> IO Ptr)
63+ msgs <- foreign FFI_C "idris_checkMessagesFrom" (Ptr -> Int -> Ptr -> IO Ptr)
60− prim__vm channel sender
64+ me channel sender
61 null <- nullPtr msgs
65 null <- nullPtr msgs
62 pure (not null)
66 pure (not null)
@@ -66,8 +70,8 @@ checkMsgsFrom sender channel
66||| Note that this is not at all type safe! It is intended to be used in
70||| Note that this is not at all type safe! It is intended to be used in
67||| a type safe wrapper.
71||| a type safe wrapper.
68getMsg : IO a
72getMsg : IO a
73+getMsg {a} = do me <- getMyVM
69−getMsg {a} = do m <- foreign FFI_C "idris_recvMessage"
74+ m <- foreign FFI_C "idris_recvMessage" (Ptr -> IO Ptr) me
70− (Ptr -> IO Ptr) prim__vm
71 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
@@ -77,8 +81,9 @@ getMsg {a} = do m <- foreign FFI_C "idris_recvMessage"
77||| a type safe wrapper.
81||| a type safe wrapper.
78getMsgWithSender : IO (Ptr, Int, a)
82getMsgWithSender : IO (Ptr, Int, a)
79getMsgWithSender {a}
83getMsgWithSender {a}
80− = do m <- foreign FFI_C "idris_recvMessage"
85+ m <- foreign FFI_C "idris_recvMessage"
81− (Ptr -> IO Ptr) prim__vm
86+ (Ptr -> IO Ptr) me
82 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
87 MkRaw x <- foreign FFI_C "idris_getMsg" (Ptr -> IO (Raw a)) m
83 vm <- sender m
88 vm <- sender m
84 chan <- channel_id m
89 chan <- channel_id m
@@ -90,8 +95,9 @@ getMsgWithSender {a}
91getMsgFrom : Ptr -> (channel : Int) -> IO (Maybe a)
96getMsgFrom : Ptr -> (channel : Int) -> IO (Maybe a)
92getMsgFrom {a} sender channel
97getMsgFrom {a} sender channel
93− = do m <- foreign FFI_C "idris_recvMessageFrom"
99+ m <- foreign FFI_C "idris_recvMessageFrom"
94− (Ptr -> Int -> Ptr -> IO Ptr) prim__vm channel sender
100+ (Ptr -> Int -> Ptr -> IO Ptr) me channel sender
95 null <- nullPtr m
101 null <- nullPtr m
97 then pure Nothing
103 then pure Nothing