Import Upstream version 20180207
[hcoop/debian/mlton.git] / lib / cml / core-cml / rep-types.sml
... / ...
CommitLineData
1(* rep-types.sml
2 * 2004 Matthew Fluet (mfluet@acm.org)
3 * Ported to MLton threads.
4 *)
5
6(* rep-types.sml
7 *
8 * COPYRIGHT (c) 1995 AT&T Bell Laboratories.
9 * COPYRIGHT (c) 1989-1991 John H. Reppy
10 *
11 * These are the concrete representations of the various CML types.
12 * These types are abstract (or not even visible) outside this library.
13 *)
14
15structure RepTypes =
16 struct
17 (** transaction IDs -- see trans-id.sml *)
18 datatype trans_id = TXID of trans_id_state ref
19 and trans_id_state =
20 CANCEL
21 | TRANS
22
23 (** condition variables --- see cvar.sml and events.sml *)
24 datatype cvar = CVAR of cvar_state ref
25 and cvar_state =
26 CVAR_unset of {transId : trans_id,
27 cleanUp : unit -> unit,
28 thread : rdy_thread} list
29 | CVAR_set of int
30
31 (** thread IDs --- see thread-id.sml and threads.sml **)
32 and thread_id =
33 TID of {
34 (* an unique ID *)
35 id : int,
36 (* true, if there is a pending alert on this thread *)
37 alert : bool ref,
38 (* set this whenever this thread does some concurrency operation. *)
39 done_comm : bool ref,
40 (* root-level exception handler hook *)
41 exnHandler : (exn -> unit) ref,
42 (* holds thread-local properties *)
43 props : exn list ref,
44 (* the cvar that becomes set when the thread dies *)
45 dead : cvar
46 }
47
48 (** threads --- see scheduler.sml and threads.sml **)
49 and 'a thread = THRD of thread_id * 'a MLton.Thread.t
50 and rdy_thread = RTHRD of thread_id * MLton.Thread.Runnable.t
51
52 (** events --- see events.sml **)
53 datatype 'a status =
54 ENABLED of {prio : int, doitFn : unit -> 'a}
55 | BLOCKED of {transId : trans_id,
56 cleanUp : unit -> unit,
57 next : unit -> rdy_thread} -> 'a
58 type 'a base = unit -> 'a status
59 datatype 'a event =
60 BEVT of 'a base list
61 | CHOOSE of 'a event list
62 | GUARD of unit -> 'a event
63 | WNACK of unit event -> 'a event
64 end