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

SCM Repository

[smlnj] Diff of /sml/trunk/src/cml/src/IO/new-text-io-fn.sml
ViewVC logotype

Diff of /sml/trunk/src/cml/src/IO/new-text-io-fn.sml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1322, Mon Apr 21 14:01:59 2003 UTC revision 1323, Sat May 10 03:37:36 2003 UTC
# Line 259  Line 259 
259                  (data, findEOS buf)                  (data, findEOS buf)
260                end                end
261    
         fun input1Evt _ = raise Fail "input1Evt unimplemented"  
         fun inputEvt _ = raise Fail "inputEvt unimplemented"  
         fun inputNEvt _ = raise Fail "inputNEvt unimplemented"  
         fun inputAllEvt _ = raise Fail "inputAllEvt unimplemented"  
         fun inputLineEvt _ = raise Fail "inputLineEvt unimplemented"  
   
262        (* Return SOME k, if k <= amount characters can be read without blocking. *)        (* Return SOME k, if k <= amount characters can be read without blocking. *)
263          fun canInput (strm as ISTRM(buf, pos), amount) = let          fun canInput (strm as ISTRM(buf, pos), amount) = let
264  (******  (******
# Line 477  Line 471 
471                  (V.concat data, strm)                  (V.concat data, strm)
472                end                end
473    
474        (* IO event constructors:
475         * We exploit the "functional" nature of stream IO to implement the event
476         * constructors.  These constructors spawn a thread to do the operation
477         * and and write the result in an iVar that serves as the synchronization
478         * value.
479         * NOTE: this implementation has the weakness that it prevents shutdown when
480         * everything else is deadlocked, since the thread that is spawned to actually
481         * do the IO could proceed.
482         *)
483            local
484              datatype 'a result = RES of 'a | EXN of exn
485              fun doInput inputOp = let
486                    fun input arg = RES(inputOp arg) handle ex => EXN ex
487                    in
488                      fn arg => CML.guard (fn () => let
489                            val resV = SV.iVar()
490                            in
491                              CML.spawn (fn () => SV.iPut(resV, input arg));
492                              CML.wrap(SV.iGetEvt resV,
493                                fn (RES x) => x | (EXN ex) => raise ex)
494                            end)
495                    end
496            in
497            val input1Evt = doInput input1
498            val inputEvt = doInput input
499            val inputNEvt = doInput inputN
500            val inputAllEvt = doInput inputAll
501            val inputLineEvt = doInput inputLine
502            end (* local *)
503    
504    
505        (*** Output streams ***)        (*** Output streams ***)
506    
507        (* an output stream is implemented as a monitor using an mvar to        (* an output stream is implemented as a monitor using an mvar to

Legend:
Removed from v.1322  
changed lines
  Added in v.1323

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