-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some fixes discovered on high usage of Miou.call and Miou.Queue #36
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -107,8 +107,7 @@ let length t = | |||
let head, tail = snapshot t in | ||||
tail.count - head.count | ||||
|
||||
let iter ~f t = | ||||
let head, tail = snapshot t in | ||||
let iter ~f (head, tail) = | ||||
let rec go prev = | ||||
if prev != tail then | ||||
match Atomic.get prev.next with | ||||
|
@@ -117,18 +116,13 @@ let iter ~f t = | |||
in | ||||
go head | ||||
|
||||
let rec drop ~f t = | ||||
let head, tail = snapshot t in | ||||
if Atomic.compare_and_set t.head head tail then ( | ||||
let rec go prev = | ||||
if prev != tail then | ||||
match Atomic.get prev.next with | ||||
| None -> () | ||||
| Some next -> f next.value; go next | ||||
in | ||||
go head; | ||||
tail.value <- Obj.magic ()) | ||||
else drop ~f t | ||||
let rec drop t = | ||||
let ((head, tail) as snapshot) = snapshot t in | ||||
if Atomic.compare_and_set t.head head tail | ||||
then snapshot else drop t | ||||
|
||||
let drop ~f t = iter ~f (drop t) | ||||
let iter ~f t = iter ~f (snapshot t) | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that Line 63 in 9d18413
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. More precisely, this is what I encountered on my project. I suspected that this version will help me but it's not - and it's why I decided to switch to a mutex + a simple queue. If you have an idea to have an atomic |
||||
|
||||
let to_list t = | ||||
let res = ref [] in | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,8 +52,8 @@ end = struct | |
| Awaiting (fn, x, y) as seen -> | ||
if Atomic.compare_and_set t seen Signaled then fn t x y else signal t | ||
|
||
let is_signaled t = Atomic.get t == Signaled | ||
let is_initial t = Atomic.get t == Initial | ||
let is_signaled t = Atomic.get t = Signaled | ||
let is_initial t = Atomic.get t = Initial | ||
Comment on lines
+55
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but I prefer to be conservative on this space. I mean, it's hard to remember all reasons that it's currently safe to user There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is indeed the model I could have had in the first place, but this issue still makes me break out in a cold sweat over the use of |
||
let[@inline never] awaiting () = invalid_arg "Trigger: already awaiting" | ||
|
||
let rec on_signal t x y fn = | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has a space leak. The problem is that, unless the queue is already empty, the node pointed to by
tail
still has a value and after a successfulcompare_and_set
that value will still be pointed to by the queue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, that's the bug I encountered on another project. I'm not sure how to implement a atomic
drop
unfortunately. I decided to switch to a mutex + a simple queue.