Skip to content

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

Merged
notgull merged 2 commits into
masterfrom
notgull/singlet
Apr 26, 2024
Merged

Move fetch_and after the prev_value check in ConcurrentQueue::single::force_push#71
notgull merged 2 commits into
masterfrom
notgull/singlet

Conversation

@notgull
Copy link
Copy Markdown
Contributor

@notgull notgull commented Apr 23, 2024

@taiki-e
Copy link
Copy Markdown
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)
                };

notgull added 2 commits April 24, 2024 19:30
cc #58 (comment)

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

notgull commented Apr 25, 2024

Good point. I've adopted this strategy here.

@notgull notgull merged commit 5b74dc8 into master Apr 26, 2024
@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