File tree Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Expand file tree Collapse file tree 1 file changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -41,33 +41,39 @@ end = struct
41
41
let is_full_unsafe t = t.capacity < = Queue. length t.queue
42
42
43
43
let push t x =
44
+ let was_full = ref false in
44
45
Lock. acquire t.lock;
45
46
match
46
47
while is_full_unsafe t do
48
+ was_full := true ;
47
49
Lock.Condition. wait t.not_full t.lock
48
50
done
49
51
with
50
52
| () ->
51
53
Queue. push x t.queue;
52
54
let n = Queue. length t.queue in
53
55
Lock. release t.lock;
54
- if n = 1 then Lock.Condition. broadcast t.not_empty
56
+ if n = 1 then Lock.Condition. signal t.not_empty;
57
+ if ! was_full && n < t.capacity then Lock.Condition. signal t.not_full
55
58
| exception exn ->
56
59
Lock. release t.lock;
57
60
raise exn
58
61
59
62
let pop t =
63
+ let was_empty = ref false in
60
64
Lock. acquire t.lock;
61
65
match
62
66
while Queue. length t.queue = 0 do
67
+ was_empty := true ;
63
68
Lock.Condition. wait t.not_empty t.lock
64
69
done
65
70
with
66
71
| () ->
67
72
let n = Queue. length t.queue in
68
73
let elem = Queue. pop t.queue in
69
74
Lock. release t.lock;
70
- if n = t.capacity then Lock.Condition. broadcast t.not_full;
75
+ if n = t.capacity then Lock.Condition. signal t.not_full;
76
+ if ! was_empty && 1 < n then Lock.Condition. signal t.not_empty;
71
77
elem
72
78
| exception exn ->
73
79
Lock. release t.lock;
@@ -78,7 +84,7 @@ end = struct
78
84
let n = Queue. length t.queue in
79
85
let elem_opt = Queue. take_opt t.queue in
80
86
Lock. release t.lock;
81
- if n = t.capacity then Lock.Condition. broadcast t.not_full;
87
+ if n = t.capacity then Lock.Condition. signal t.not_full;
82
88
elem_opt
83
89
end
84
90
You can’t perform that action at this time.
0 commit comments