1
(* $Id: netsys_oothr.ml 1529 2011-01-04 01:37:10Z gerd $ *)
3
class type mtprovider =
5
method single_threaded : bool
6
method create_thread : 's 't . ('s -> 't) -> 's -> thread
8
method yield : unit -> unit
9
method create_mutex : unit -> mutex
10
method create_condition : unit -> condition
16
method join : unit -> unit
22
method lock : unit -> unit
23
method unlock : unit -> unit
24
method try_lock : unit -> bool
30
method wait : mutex -> unit
31
method signal : unit -> unit
32
method broadcast : unit -> unit
36
(* single-threaded dummy stuff: *)
40
let stthread() : thread =
44
failwith "Netsys_oothr: join not possible in single-threaded program"
49
let stmutex() : mutex =
53
method try_lock() = true
58
let stcondition() : condition =
62
method broadcast() = ()
67
let stprovider : mtprovider =
69
method single_threaded = true
70
method create_thread : 's 't . ('s -> 't) -> 's -> thread =
71
fun _ _ -> failwith "Netsys_oothr: create_thread not possible in single-threaded program"
72
method self = stthread()
74
method create_mutex() = stmutex()
75
method create_condition() = stcondition()
79
let provider = ref stprovider
80
let single_threaded = ref false (* whether we know this for sure *)
81
let st_init = ref false
83
let serialize mutex f arg =
84
if !single_threaded then (
88
if not !st_init then (
89
single_threaded := !provider # single_threaded;
95
with e -> mutex # unlock(); raise e in