Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Replace Scope with Guard #31

Merged
6 commits merged into from Nov 20, 2017
Merged

Replace Scope with Guard #31

6 commits merged into from Nov 20, 2017

Conversation

ghost
Copy link

@ghost ghost commented Nov 3, 2017

Apologies for the huge PR. I'll try to summarize what's going on here:

  1. atomic.rs - No big changes, &Scope was just changed to &Guard.
  2. collector.rs - Handle::clone now creates another reference instead of a new handle.
  3. epoch.rs - Almost everything is new. I've implemented types Epoch and AtomicEpoch, which are similar to usize and AtomicUsize.
  4. guard.rs - No big deal, just a lot of documentation.
  5. internal.rs - The meatiest part of this PR.
  6. sync/list.rs - This file is gone. I've found it easier to work directly with the linked list in internal.rs rather than through a List<T> abstraction. But we could bring List<T> back in a future PR, though.
  7. sync/queue.rs - Scopes replaced with guards, that's all.

Closes #25.

@ghost
Copy link
Author

ghost commented Nov 17, 2017

@jeehoonkang Just a reminder that this is waiting for review. :)

Copy link
Contributor

@jeehoonkang jeehoonkang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides minor comments, I'm happy with all the changes. Thanks!

But I'm a little bit hesitant to merge this PR now, because the following issue has not been resolved yet: crossbeam-rs/rfcs#23 In order to address the issue, maybe we need to once more change this repo.

What do you think?

/// Decomposes the internal data into the epoch and the pin state.
#[inline]
fn decompose(&self) -> (usize, bool) {
(self.data >> 1, (self.data & 1) == 1)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about returning (self.data, (self.data & 1) == 1)? Maybe it's a little bit more difficult interface to use, but may we can save an instruction 😃

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, it's just a shift operation that gets executed on cold paths, so it doesn't really matter... :)

src/guard.rs Outdated
#[inline]
pub unsafe fn unprotected() -> &'static Guard {
static UNPROTECTED: usize = 0;
&*(&UNPROTECTED as *const _ as *const Guard)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't figure out why it is safe -- would you please explain a little bit more?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an explanation.

pin_count: Cell<usize>,
///
/// This is just an auxilliary counter that sometimes kicks off collection.
pin_count: Cell<Wrapping<usize>>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow, Wrapping is very convenient :)

@ghost
Copy link
Author

ghost commented Nov 20, 2017

@jeehoonkang Do you think we could merge this now and release version 0.1.0?
I'd like to release a 0.1.0 so that crossbeam-deque and crossbeam-channel can start depending on it. Then I could finally deprecate coco and switch rayon onto crossbeam. :)

Regarding crossbeam-rs/rfcs#23, I think we will have to make slight adjustments to Collector or Guard either way, but figuring that out will again take some time.

@ghost
Copy link
Author

ghost commented Nov 20, 2017

Also, I forgot to ask:

Do you have an opinion on whether unprotected() should return a &'static Guard or a Guard? Originally I decided to go with returning a reference, but now I'm not so sure that was the right choice...

@jeehoonkang
Copy link
Contributor

@stjepang I also thought of releasing 0.1.0 after merging it, but was also concerned with backward compatibility. If we release it now, it's quite clear that 0.2.0 will break some API. That's legal in semantic versioning scheme, but still it's better to avoid breaking changes if we can..

On the other hand, crossbeam-epoch 0.1.0 is so waited in many parties, including crossbeam itself and rayon If we can provide a clear migration path from 0.1.0 to 0.2.0, breaking changes will not be fatally painful.

I'm torn between the two options, but anyway I'm willing to follow your decision. Let's merge it!

I'd like to say thank you for your great job!

@jeehoonkang
Copy link
Contributor

jeehoonkang commented Nov 20, 2017

On unprotected(): I'm also not sure of this issue, but I think it's easier to change the API from returning &'static Guard to returning Guard than the other way around. How about beginning with a more strict API, and relaxing it later when use cases demand it?

@ghost ghost merged commit 88ef2c5 into crossbeam-rs:master Nov 20, 2017
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant