@@ -41,26 +41,26 @@ let with_lock_ q f =
41
41
let push q x =
42
42
with_lock_ q
43
43
(fun () ->
44
- while q.size = q.capacity do
45
- Condition. wait q.cond q.lock
46
- done ;
47
- assert (q.size < q.capacity);
48
- Queue. push x q.q;
49
- (* if there are blocked receivers, awake one of them *)
50
- incr_size_ q;
51
- Condition. broadcast q.cond)
44
+ while q.size = q.capacity do
45
+ Condition. wait q.cond q.lock
46
+ done ;
47
+ assert (q.size < q.capacity);
48
+ Queue. push x q.q;
49
+ (* if there are blocked receivers, awake one of them *)
50
+ incr_size_ q;
51
+ Condition. broadcast q.cond)
52
52
53
53
let take q =
54
54
with_lock_ q
55
55
(fun () ->
56
- while q.size = 0 do
57
- Condition. wait q.cond q.lock
58
- done ;
59
- let x = Queue. take q.q in
60
- (* if there are blocked senders, awake one of them *)
61
- decr_size_ q;
62
- Condition. broadcast q.cond;
63
- x)
56
+ while q.size = 0 do
57
+ Condition. wait q.cond q.lock
58
+ done ;
59
+ let x = Queue. take q.q in
60
+ (* if there are blocked senders, awake one of them *)
61
+ decr_size_ q;
62
+ Condition. broadcast q.cond;
63
+ x)
64
64
65
65
(* $R
66
66
let q = create 1 in
@@ -83,22 +83,22 @@ let push_list q l =
83
83
| [] -> l
84
84
| _ ::_ when q.size = q.capacity -> l (* no room remaining *)
85
85
| x :: tl ->
86
- Queue. push x q.q;
87
- incr_size_ q;
88
- push_ q tl
86
+ Queue. push x q.q;
87
+ incr_size_ q;
88
+ push_ q tl
89
89
in
90
90
(* push chunks of [l] in [q] until [l] is empty *)
91
91
let rec aux q l = match l with
92
- | [] -> ()
93
- | _ ::_ ->
92
+ | [] -> ()
93
+ | _ ::_ ->
94
94
let l = with_lock_ q
95
- (fun () ->
96
- while q.size = q.capacity do
97
- Condition. wait q.cond q.lock
98
- done ;
99
- let l = push_ q l in
100
- Condition. broadcast q.cond;
101
- l)
95
+ (fun () ->
96
+ while q.size = q.capacity do
97
+ Condition. wait q.cond q.lock
98
+ done ;
99
+ let l = push_ q l in
100
+ Condition. broadcast q.cond;
101
+ l)
102
102
in
103
103
aux q l
104
104
in aux q l
@@ -118,14 +118,14 @@ let take_list q n =
118
118
if n= 0 then List. rev acc
119
119
else
120
120
let acc, n = with_lock_ q
121
- (fun () ->
122
- while q.size = 0 do
123
- Condition. wait q.cond q.lock
124
- done ;
125
- let acc, n = pop_ acc q n in
126
- Condition. broadcast q.cond;
127
- acc, n
128
- )
121
+ (fun () ->
122
+ while q.size = 0 do
123
+ Condition. wait q.cond q.lock
124
+ done ;
125
+ let acc, n = pop_ acc q n in
126
+ Condition. broadcast q.cond;
127
+ acc, n
128
+ )
129
129
in
130
130
aux acc q n
131
131
in
@@ -163,28 +163,28 @@ let take_list q n =
163
163
let try_take q =
164
164
with_lock_ q
165
165
(fun () ->
166
- if q.size = 0 then None
167
- else (
168
- decr_size_ q;
169
- Some (Queue. take q.q)
170
- ))
166
+ if q.size = 0 then None
167
+ else (
168
+ decr_size_ q;
169
+ Some (Queue. take q.q)
170
+ ))
171
171
172
172
let try_push q x =
173
173
with_lock_ q
174
174
(fun () ->
175
- if q.size = q.capacity then false
176
- else (
177
- incr_size_ q;
178
- Queue. push x q.q;
179
- Condition. signal q.cond;
180
- true
181
- ))
175
+ if q.size = q.capacity then false
176
+ else (
177
+ incr_size_ q;
178
+ Queue. push x q.q;
179
+ Condition. signal q.cond;
180
+ true
181
+ ))
182
182
183
183
let peek q =
184
184
with_lock_ q
185
185
(fun () ->
186
- try Some (Queue. peek q.q)
187
- with Queue. Empty -> None )
186
+ try Some (Queue. peek q.q)
187
+ with Queue. Empty -> None )
188
188
189
189
let size q = with_lock_ q (fun () -> q.size)
190
190
0 commit comments