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

sync ops for queue #899

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

conradludgate
Copy link

I was looking to see if I could replace the Mutex<VecDeque<T>> from the deadpool crate, but there's an interesting requirement here - deadpool has a resize method that can resize the queue.

Not to be deterred, I am hoping to use a RwLock<ArrayQueue<T>>. 99% of ops will call slots.read().pop(), but for the resize function, I was intending to use slots.write() to get sole ownership, then I could mem::swap in a new queue. This would be fine, but I thought it could be more efficient.

This PR introduces an efficient implementation of some of the sync (&mut self) operations for inserting into the queue, as well as that resize method.

pop_sync,push_sync,force_push_sync are much like their shared counterparts, except they don't need to care about atomic load orderings. (I'm open to alternative namings)

resize is a little more complicated:

  1. We 'reset' the queue. This shifts all live slots to the front of the slice
  2. We take out the buffer from the queue as a vec - leaving a dangling empty box in it's place
  3. We either reserve and fill, or truncate and shrink our vec
  4. We turn our vec back into a boxed slice, and update our queue to match

@conradludgate
Copy link
Author

Developing for older MSRVs on an M1 mac is hard 🙃 the minimum rust I can install is 1.49

@taiki-e
Copy link
Member

taiki-e commented Aug 21, 2022

Developing for older MSRVs on an M1 mac is hard 🙃 the minimum rust I can install is 1.49

FYI, you can use rustup toolchain add 1.38-x86_64-apple-darwin and cargo +1.38-x86_64-apple-darwin build.

@conradludgate
Copy link
Author

Developing for older MSRVs on an M1 mac is hard 🙃 the minimum rust I can install is 1.49

FYI, you can use rustup toolchain add 1.38-x86_64-apple-darwin and cargo +1.38-x86_64-apple-darwin build.

Thanks, it seems to build locally now 😅

@conradludgate
Copy link
Author

Ok - I'm in no rush for this to get reviewed. Having swapped out the deadpool queue for this impl, I get noticeable regressions for some reason :(

@taiki-e taiki-e marked this pull request as draft August 22, 2022 03:58
@taiki-e
Copy link
Member

taiki-e commented Aug 22, 2022

Ok, marked this as draft for now.

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