Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/cml/cml-lib/simple-rpc.sml
ViewVC logotype

Annotation of /sml/trunk/src/cml/cml-lib/simple-rpc.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 290 - (view) (download)

1 : monnier 2 (* simple-rpc.sml
2 :     *
3 :     * COPYRIGHT (c) 1997 AT&T Labs Research.
4 :     *
5 :     * Generators for simple RPC protocols.
6 :     *)
7 :    
8 :     structure SimpleRPC : SIMPLE_RPC =
9 :     struct
10 :    
11 :     type 'a event = 'a CML.event
12 :    
13 : monnier 289 fun call reqMB arg = let
14 :     val replV = SyncVar.iVar()
15 :     in
16 :     Mailbox.send(reqMb, (arg, replV));
17 :     SyncVar.iGet replV
18 :     end
19 :    
20 : monnier 2 fun mkRPC f = let
21 :     val reqMb = Mailbox.mailbox()
22 : monnier 289 val entryEvt = CML.wrap (
23 :     Mailbox.recvEvt reqMb,
24 : monnier 2 fn (arg, replV) => SyncVar.iPut(replV, f arg))
25 :     in
26 : monnier 289 { call = call reqMB, entryEvt = entryEvt }
27 : monnier 2 end
28 :    
29 :     fun mkRPC_In f = let
30 :     val reqMb = Mailbox.mailbox()
31 :     val reqEvt = Mailbox.recvEvt reqMb
32 : monnier 289 fun entryEvt state = CML.wrap (
33 : monnier 2 reqEvt,
34 :     fn (arg, replV) => SyncVar.iPut(replV, f(arg, state)))
35 :     in
36 : monnier 289 { call = call reqMB, entryEvt = entryEvt }
37 : monnier 2 end
38 :    
39 : monnier 289 fun mkRPC_Out f = let
40 :     val reqMb = Mailbox.mailbox()
41 :     val reqEvt = Mailbox.recvEvt reqMb
42 :     val entryEvt = CML.wrap (
43 :     reqEvt,
44 :     fn (arg, replV) => let val (res, state') = f arg
45 :     in
46 :     SyncVar.iPut(replV, res); state'
47 :     end)
48 :     in
49 :     { call = call reqMB, entryEvt = entryEvt }
50 :     end
51 :    
52 : monnier 2 fun mkRPC_InOut f = let
53 :     val reqMb = Mailbox.mailbox()
54 :     val reqEvt = Mailbox.recvEvt reqMb
55 : monnier 289 fun entryEvt state = CML.wrap (
56 : monnier 2 reqEvt,
57 :     fn (arg, replV) => let val (res, state') = f(arg, state)
58 :     in
59 :     SyncVar.iPut(replV, res); state'
60 :     end)
61 :     in
62 : monnier 289 { call = call reqMB, entryEvt = entryEvt }
63 : monnier 2 end
64 :    
65 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0