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

SCM Repository

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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (download) (annotate)
Sat Oct 4 23:33:09 1997 UTC (21 years, 9 months ago) by monnier
File size: 1355 byte(s)
Initial revision
(* simple-rpc.sml
 *
 * COPYRIGHT (c) 1997 AT&T Labs Research.
 *
 * Generators for simple RPC protocols.
 *)

structure SimpleRPC : SIMPLE_RPC =
  struct

    type 'a event = 'a CML.event

    fun mkRPC f = let
	  val reqMb = Mailbox.mailbox()
	  fun call arg = let
		val replV = SyncVar.iVar()
		in
		  Mailbox.send(reqMb, (arg, replV));
		  SyncVar.iGet replV
		end
	  val reqEvt = Mailbox.recvEvt reqMb
	  val entry = CML.wrap (
		reqEvt,
		fn (arg, replV) => SyncVar.iPut(replV, f arg))
	  in
	    { call = call, entryEvt = entry }
	  end

    fun mkRPC_In f = let
	  val reqMb = Mailbox.mailbox()
	  fun call arg = let
		val replV = SyncVar.iVar()
		in
		  Mailbox.send(reqMb, (arg, replV));
		  SyncVar.iGet replV
		end
	  val reqEvt = Mailbox.recvEvt reqMb
	  fun entry state = CML.wrap (
		reqEvt,
		fn (arg, replV) => SyncVar.iPut(replV, f(arg, state)))
	  in
	    { call = call, entryEvt = entry }
	  end

    fun mkRPC_InOut f = let
	  val reqMb = Mailbox.mailbox()
	  fun call arg = let
		val replV = SyncVar.iVar()
		in
		  Mailbox.send(reqMb, (arg, replV));
		  SyncVar.iGet replV
		end
	  val reqEvt = Mailbox.recvEvt reqMb
	  fun entry state = CML.wrap (
		reqEvt,
		fn (arg, replV) => let val (res, state') = f(arg, state)
		  in
		    SyncVar.iPut(replV, res); state'
		  end)
	  in
	    { call = call, entryEvt = entry }
	  end

  end

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