-
Notifications
You must be signed in to change notification settings - Fork 54
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
Add functions to take/release just producer or consumer #78
Conversation
Ping @jamesmunns (due to draft PR) |
Apparently, yes: https://github.com/jamesmunns/bbqueue/runs/1390103704 Edit: this is now implemented |
7ecf2de
to
4a37dd9
Compare
Yes, I would suggest doing either on the first one that is taken, or doing it for the consumer alone is probably enough. Otherwise it is undefined behavior.
This is optional. It's generally not safe to do unless BOTH halves have been released. When in doubt, skip it. |
This has been implemented in de43a30 Zeroes on |
Hey @timvisee, I'll plan on reviewing this PR this weekend, but I realized that I was wrong - you'll need to zero-init the buffer when the PRODUCER (not consumer) is taken - as the producer will be the one to "see" the contents of the data first (e.g. if a producer is taken, then a grant is requested, the grant will be able to "see" uninitialized data if no consumer has been taken). Sorry for the wrong guidance before. |
de43a30
to
03b9774
Compare
@jamesmunns It now zeroes when the producer is taken. I amended this change to the last commit (03b9774). |
885e342
to
88ee375
Compare
88ee375
to
9a0a2cf
Compare
Will conflict with #103 |
@Sympatron Thanks! I'll rebase and reevaluate this PR later today. I did not keep track of all the recent changes and so this may very well not be valid anymore. |
Some changes will be necessary, because #103 uses |
Just rebasing turned out to be more difficult than I had anticipated. I think it'd be better to implement this from scratch. Sadly, I currently don't have the resources available to do so. If someone else wants to make the effort, please feel free! I consider this PR stale and will therefore close it now. |
This implements:
BBBuffer::try_take_producer
: split-off just the producerBBBuffer::try_take_consumer
: split-off just the consumerBBBuffer::try_release_producer
: release (give back) just the producerBBBuffer::try_release_consumer
: release (give back) just the consumerI choose to use an
AtomicU8
for thealready_split
state with a bit for the producer and consumer parts which are defined inBIT_PRODUCER
andBIT_CONSUMER
respectively. I thought this would be the right approach as updating the state for both the producer and consumer can still be done in a single atomic operation. That wouldn't be the case when using two separateAtomicBool
's.Things to resolve before merge:
try_split
? (currently commented-out)try_release
?fetch_or
andfetch_add
, do we need to implement this forthumbv6
?The above things I'm currently uncertain about. My knowledge is lacking on this, thus I'd like to ask to make sure the implementation is sound. The PR branch is open, so feel free to make an edit.
Fixes #40
Related #67