-
Notifications
You must be signed in to change notification settings - Fork 31
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
pop_opt
, peek
, peek_opt
functions for queue
#92
Conversation
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.
Comments about how and where to use [@inline]
.
let b = Backoff.create () in | ||
let rec loop () = | ||
let old_head = Atomic.get head in | ||
match Atomic.get old_head with | ||
| Nil -> raise Empty | ||
| Next (value, next) when Atomic.compare_and_set head old_head next -> value | ||
| _ -> | ||
Backoff.once b; | ||
loop () | ||
in | ||
loop () |
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 is the same function as pop_opt
except for very small changes. Should I use [@inline]
and a generic pop function ?
src_lockfree/spsc_queue.ml
Outdated
let[@inline] try_push t element = | ||
try | ||
push t element; | ||
true | ||
with Full -> false |
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.
Here I try the [@inline]
. But I don't think this is the right way to use it. Any help will be welcomed.
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.
LGTM. Minor typo below.
|
||
@raise Empty if [q] is empty. *) | ||
|
||
val pop_opt : 'a t -> 'a option |
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.
Function name is not edited in the line below.
This PR renames and adds functions to the single consumer single producer queue, the michael-scott queue, the treiber stack and the multiple producer single consumer queue.
pop
is renamedpop_opt
pop
raisesEmpty
if the queue is emptypeek
andpeek_opt
have been added as well (except for the stack)Other notes :
peek
functions, as it seems useless (it is useful mostly with a single consumer).clean_until
function as it was no atomic.TODO :
Rename,pop
topop_opt
for relaxed-queuepop
topop_opt
for the work-stealing dequepop
andpop_opt
be almost copy-paste function or should we use theinline
keyword (see comment in code)