Skip to content
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

Move fetch_and after the prev_value check in ConcurrentQueue::single::force_push #71

Merged
merged 2 commits into from
Apr 26, 2024

Conversation

notgull
Copy link
Member

@notgull notgull commented Apr 23, 2024

@taiki-e
Copy link
Collaborator

taiki-e commented Apr 23, 2024

Sorry, I meant handling the memory accesses themselves in the branch as well. And this seems to be useful even when optimization is enabled (godbolt)

                // If the value was pushed, swap out the value.
                let prev_value = if prev & PUSHED == 0 {
                    // SAFETY: write is safe because we have locked the state.
                    self.slot.with_mut(|slot| unsafe {
                        slot.write(MaybeUninit::new(value));
                    });
                    None
                } else {
                    // SAFETY: replace is safe because we have locked the state, and
                    // assume_init is safe because we have checked that the value was pushed.
                    let prev_value = unsafe {
                        self.slot
                            .with_mut(move |slot| ptr::replace(slot, MaybeUninit::new(value)).assume_init())
                    };
                    Some(prev_value)
                };

cc #58 (comment)

Signed-off-by: John Nunley <dev@notgull.net>
Signed-off-by: John Nunley <dev@notgull.net>
@notgull
Copy link
Member Author

notgull commented Apr 25, 2024

Good point. I've adopted this strategy here.

@notgull notgull merged commit 5b74dc8 into master Apr 26, 2024
9 checks passed
@notgull notgull deleted the notgull/singlet branch April 26, 2024 05:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants