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