Skip to content

Commit b944606

Browse files
committed
Elimination des evenements non selectionnes
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@2325 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
1 parent ef9b999 commit b944606

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

otherlibs/systhreads/event.ml

+15-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,10 @@ type 'a event =
2828

2929
(* Communication channels *)
3030
type 'a channel =
31-
{ writes_pending: 'a communication Queue.t; (* All offers to write on it *)
32-
reads_pending: 'a communication Queue.t } (* All offers to read from it *)
31+
{ mutable writes_pending: 'a communication Queue.t;
32+
(* All offers to write on it *)
33+
mutable reads_pending: 'a communication Queue.t }
34+
(* All offers to read from it *)
3335

3436
(* Communication offered *)
3537
and 'a communication =
@@ -125,6 +127,13 @@ let basic_poll genev =
125127
let poll ev =
126128
basic_poll(scramble_array(Array.of_list(flatten_event ev [])))
127129

130+
(* Remove all communication opportunities already synchronized *)
131+
132+
let cleanup_queue q =
133+
let q' = Queue.create() in
134+
Queue.iter (fun c -> if !(c.performed) = -1 then Queue.add c q') q;
135+
q'
136+
128137
(* Event construction *)
129138

130139
let always data =
@@ -156,7 +165,9 @@ let send channel data =
156165
true
157166
with Queue.Empty ->
158167
false);
159-
suspend = (fun () -> Queue.add wcomm channel.writes_pending);
168+
suspend = (fun () ->
169+
channel.writes_pending <- cleanup_queue channel.writes_pending;
170+
Queue.add wcomm channel.writes_pending);
160171
result = (fun () -> ()) })
161172

162173
let receive channel =
@@ -183,6 +194,7 @@ let receive channel =
183194
with Queue.Empty ->
184195
false);
185196
suspend = (fun () ->
197+
channel.reads_pending <- cleanup_queue channel.reads_pending;
186198
Queue.add rcomm channel.reads_pending);
187199
result = (fun () ->
188200
match rcomm.data with

0 commit comments

Comments
 (0)