Commit | Line | Data |
---|---|---|
7f918cf1 CE |
1 | (* Copyright (C) 2009 Matthew Fluet. |
2 | * Copyright (C) 2004-2006 Henry Cejtin, Matthew Fluet, Suresh | |
3 | * Jagannathan, and Stephen Weeks. | |
4 | * | |
5 | * MLton is released under a BSD-style license. | |
6 | * See the file MLton-LICENSE for details. | |
7 | *) | |
8 | ||
9 | signature MLTON_THREAD = | |
10 | sig | |
11 | structure AtomicState : | |
12 | sig | |
13 | datatype t = NonAtomic | Atomic of int | |
14 | end | |
15 | val atomically: (unit -> 'a) -> 'a | |
16 | val atomicBegin: unit -> unit | |
17 | val atomicEnd: unit -> unit | |
18 | val atomicState: unit -> AtomicState.t | |
19 | ||
20 | structure Runnable : | |
21 | sig | |
22 | type t | |
23 | end | |
24 | ||
25 | type 'a t | |
26 | ||
27 | (* atomicSwitch f | |
28 | * as switch, but assumes an atomic calling context. Upon | |
29 | * switch-ing back to the current thread, an implicit atomicEnd is | |
30 | * performed. | |
31 | *) | |
32 | val atomicSwitch: ('a t -> Runnable.t) -> 'a | |
33 | (* new f | |
34 | * create a new thread that, when run, applies f to | |
35 | * the value given to the thread. f must terminate by | |
36 | * switch-ing to another thread or exiting the process. | |
37 | *) | |
38 | val new: ('a -> unit) -> 'a t | |
39 | (* prepend(t, f) | |
40 | * create a new thread (destroying t in the process) that first | |
41 | * applies f to the value given to the thread and then continues | |
42 | * with t. This is a constant time operation. | |
43 | *) | |
44 | val prepend: 'a t * ('b -> 'a) -> 'b t | |
45 | (* prepare(t, v) | |
46 | * create a new runnable thread (destroying t in the process) | |
47 | * that will evaluate t on v. | |
48 | *) | |
49 | val prepare: 'a t * 'a -> Runnable.t | |
50 | (* switch f | |
51 | * apply f to the current thread to get rt, and then start | |
52 | * running thread rt. It is an error for f to | |
53 | * perform another switch. f is guaranteed to run | |
54 | * atomically. | |
55 | *) | |
56 | val switch: ('a t -> Runnable.t) -> 'a | |
57 | end |