@@ -26,8 +26,10 @@ type return_on =
26
26
}
27
27
-> return_on
28
28
29
+ type phase = Continue | Select | Waking_up | Process
30
+
29
31
type state = {
30
- phase : [ `Select | `Continue | `Process ] Atomic .t ;
32
+ phase : phase Atomic .t ;
31
33
mutable state : [ `Initial | `Starting | `Alive | `Stopping | `Stopped ];
32
34
mutable exn_bt : Exn_bt .t ;
33
35
mutable pipe_inn : Unix .file_descr ;
@@ -47,7 +49,7 @@ let exit_exn_bt = Exn_bt.get_callstack 0 Exit
47
49
let key =
48
50
Picos_domain.DLS. new_key @@ fun () ->
49
51
{
50
- phase = Atomic. make ` Continue ;
52
+ phase = Atomic. make Continue ;
51
53
state = `Initial ;
52
54
exn_bt = exit_exn_bt;
53
55
pipe_inn = Unix. stdin;
@@ -74,11 +76,11 @@ let[@poll error] [@inline never] transition s into =
74
76
75
77
let rec wakeup s from =
76
78
match Atomic. get s.phase with
77
- | ` Process ->
79
+ | Process | Waking_up ->
78
80
(* The thread will process the fds and timeouts before next select. *)
79
81
()
80
- | ` Continue ->
81
- if Atomic. compare_and_set s.phase ` Continue ` Process then
82
+ | Continue ->
83
+ if Atomic. compare_and_set s.phase Continue Process then
82
84
(* We managed to signal the wakeup before the thread was ready to call
83
85
select and the thread will notice this without us needing to write to
84
86
the pipe. *)
@@ -87,8 +89,8 @@ let rec wakeup s from =
87
89
(* Either the thread called select or another wakeup won the race. We
88
90
need to retry. *)
89
91
wakeup s from
90
- | ` Select ->
91
- if Atomic. compare_and_set s.phase ` Select `Continue then
92
+ | Select ->
93
+ if Atomic. compare_and_set s.phase Select Waking_up then
92
94
if s.state == from then
93
95
(* We are now responsible for writing to the pipe to force the thread to
94
96
exit the select. *)
@@ -149,7 +151,7 @@ let rec process_timeouts s =
149
151
150
152
let rec select_thread s timeout rd wr ex =
151
153
if s.state == `Alive then
152
- if Atomic. compare_and_set s.phase ` Continue ` Select then
154
+ if Atomic. compare_and_set s.phase Continue Select then
153
155
begin
154
156
try
155
157
Unix. select
@@ -162,9 +164,9 @@ let rec select_thread s timeout rd wr ex =
162
164
163
165
and select_thread_continue s rd wr ex (rd_fds , wr_fds , ex_fds ) =
164
166
begin
165
- match Atomic. exchange s.phase ` Continue with
166
- | ` Select | ` Process -> ()
167
- | `Continue ->
167
+ match Atomic. exchange s.phase Continue with
168
+ | Select | Process | Continue -> ()
169
+ | Waking_up ->
168
170
let n = Unix. read s.pipe_inn s.byte 0 1 in
169
171
assert (n = 1 )
170
172
end ;
0 commit comments