on master help sign in
Rename Channels to Sessions

They're not really channels in the CSP sense because they can't be passed around. 'Session' seems more appropriate since they're meant for individual conversations (sort of like a communication between machines via a socket on a network)

commitbf108b69e3da10256fae2e2cbf9bc15e5a60f90d authorEdwin Brady <ecb10@st-andrews.ac.uk> dateThu 26 May 2016, 12:43 (10 years ago) parent2c83d47
3 files changed+12−10
CHANGELOG.md+2 libs/base/System/Concurrency/Channels.idr → libs/base/System/Concurrency/Sessions.idr+9−9 libs/base/base.ipkg+1−1
CHANGELOG.md+2
@@ -80,6 +80,8 @@
8080* Added `Data.List.Views` with views on `List` and their covering functions.
8181* Added `Data.Nat.Views` with views on `Nat` and their covering functions.
8282* Added `Data.Primitives.Views` with views on various primitive types and their covering functions.
83+* Added `System.Concurrency.Sessions` for simple management of conversations
84+ between processes
8385
8486## Miscellaneous updates
8587
libs/base/System/Concurrency/Channels.idr → libs/base/System/Concurrency/Sessions.idrrenamed+9−9
@@ -1,14 +1,14 @@
1−module System.Concurrency.Channels
1+module System.Concurrency.Sessions
22
33import System.Concurrency.Raw
44
5−||| A Channel is a connection between two processes. Channels can be created
5+||| A Session is a connection between two processes. Sessions can be created
66||| either using 'listen' to wait for an incoming connection, or 'connect'
77||| which initiates a connection to another process.
8−||| Channels cannot be passed between processes.
8+||| Sessions cannot be passed between processes.
99export
10−data Channel : Type where
11− MkConc : (pid : Ptr) -> (ch_id : Int) -> Channel
10+data Session : Type where
11+ MkConc : (pid : Ptr) -> (ch_id : Int) -> Session
1212
1313||| A PID is a process identifier, as returned by `spawn`
1414export
@@ -23,7 +23,7 @@ spawn proc = do pid <- fork proc
2323
2424||| Create a channel which connects this process to another process
2525export
26−connect : (proc : PID) -> IO (Maybe Channel)
26+connect : (proc : PID) -> IO (Maybe Session)
2727connect (MkPID pid) = do ch_id <- sendToThread pid 0 ()
2828 if (ch_id /= 0)
2929 then pure (Just (MkConc pid ch_id))
@@ -32,7 +32,7 @@ connect (MkPID pid) = do ch_id <- sendToThread pid 0 ()
3232||| Listen for incoming connections. If another process has initiated a
3333||| communication with this process, returns a channel
3434export
35−listen : (timeout : Int) -> IO (Maybe Channel)
35+listen : (timeout : Int) -> IO (Maybe Session)
3636listen timeout = do checkMsgsTimeout timeout
3737 Just (client, ch_id) <- listenMsgs
3838 | Nothing => pure Nothing
@@ -46,7 +46,7 @@ listen timeout = do checkMsgsTimeout timeout
4646||| a protocol (externally checked) which ensures that the message send
4747||| is of type expected by the receiver.
4848export
49−unsafeSend : Channel -> (val : a) -> IO Bool
49+unsafeSend : Session -> (val : a) -> IO Bool
5050unsafeSend (MkConc pid ch_id) val
5151 = do ok <- sendToThread pid ch_id val
5252 pure (ok /= 0)
@@ -58,6 +58,6 @@ unsafeSend (MkConc pid ch_id) val
5858||| a protocol (externally checked) which ensures that the message received
5959||| is of the type given by the sender.
6060export
61−unsafeRecv : (a : Type) -> Channel -> IO (Maybe a)
61+unsafeRecv : (a : Type) -> Session -> IO (Maybe a)
6262unsafeRecv a (MkConc pid ch_id) = getMsgFrom {a} pid ch_id
6363
libs/base/base.ipkg+1−1
@@ -31,5 +31,5 @@ modules = System,
3131 Control.Category, Control.Arrow,
3232 Control.Catchable, Control.IOExcept,
3333
34− System.Concurrency.Raw, System.Concurrency.Channels
34+ System.Concurrency.Raw, System.Concurrency.Sessions
3535