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

Change compare_exchange to return a Result<T, T> #32244

Merged
merged 1 commit into from
Mar 19, 2016

Conversation

Amanieu
Copy link
Member

@Amanieu Amanieu commented Mar 14, 2016

As per the discussion in #31767

I also changed the feature name from extended_compare_and_swap to compare_exchange.

r? @alexcrichton

@Amanieu Amanieu force-pushed the compare_exchange_result branch 2 times, most recently from d7e8302 to acb9256 Compare March 14, 2016 13:48
@alexcrichton
Copy link
Member

Thanks @Amanieu! From a technical perspective the change looks good to me, just a question of APIs now! I'm tagging this with T-libs to ensure it comes up during triage.

So I originally thought that this may make the classical "compare exchange loop" a little less ergnomic as getting the value out would require unwrap_or_else or something like that, but when I write them down...

current:

loop {
    let new = f(current);
    let old = foo.compare_exchange(current, new, ord1, ord2);
    if old == current {
        break
    }
    current = old;
}

new:

loop {
    let new = f(current);
    match foo.compare_exchange(current, new, ord1, ord2) {
        Ok(..) => break,
        Err(old) => current = old,
    }
}

I gotta say using match here seems quite appealing to me!

To get a handle on the ergonomics though it may be worthwhile to port a project like crossbeam to using this API instead of the old one (just as a smoke test)

@alexcrichton alexcrichton added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 14, 2016
@alexcrichton
Copy link
Member

The libs team discussed this during triage yesterday and the conclusion was that this seems like a good change to have! It was brought up though that we may not want to change the feature names as that's kinda unnecessary breakage, would you be ok changing back?

@alexcrichton alexcrichton removed the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Mar 17, 2016
@Amanieu Amanieu force-pushed the compare_exchange_result branch 2 times, most recently from cb3e048 to 2964f18 Compare March 17, 2016 23:40
@Amanieu
Copy link
Member Author

Amanieu commented Mar 17, 2016

Done

@alexcrichton
Copy link
Member

@bors: r+ 2964f1873e54b42cc3994ba8882d2486305c32c3

@bors
Copy link
Contributor

bors commented Mar 18, 2016

⌛ Testing commit 2964f18 with merge dedfe4a...

@bors
Copy link
Contributor

bors commented Mar 18, 2016

💔 Test failed - auto-mac-64-opt

@Amanieu Amanieu force-pushed the compare_exchange_result branch from 2964f18 to 928d8cd Compare March 18, 2016 09:47
@Amanieu
Copy link
Member Author

Amanieu commented Mar 18, 2016

Fixed

@Amanieu Amanieu force-pushed the compare_exchange_result branch from 928d8cd to 18222c0 Compare March 18, 2016 10:04
@eddyb
Copy link
Member

eddyb commented Mar 18, 2016

@alexcrichton This will have to wait until #32080 is merged, btw.

@bors
Copy link
Contributor

bors commented Mar 18, 2016

☔ The latest upstream changes (presumably #32080) made this pull request unmergeable. Please resolve the merge conflicts.

@Amanieu Amanieu force-pushed the compare_exchange_result branch 3 times, most recently from 4187714 to 6f0a130 Compare March 19, 2016 01:54
@Amanieu
Copy link
Member Author

Amanieu commented Mar 19, 2016

I think this should be fixed now

@alexcrichton
Copy link
Member

@bors: r+ 6f0a1307741e7d1d297aeffd2ec15eb905e1d487

@bors
Copy link
Contributor

bors commented Mar 19, 2016

⌛ Testing commit 6f0a130 with merge 424af07...

@alexcrichton
Copy link
Member

@bors: retry force clean

@bors
Copy link
Contributor

bors commented Mar 19, 2016

⌛ Testing commit 6f0a130 with merge 8021fa5...

@bors
Copy link
Contributor

bors commented Mar 19, 2016

💔 Test failed - auto-mac-64-nopt-t

@Amanieu Amanieu force-pushed the compare_exchange_result branch from 6f0a130 to 421fed1 Compare March 19, 2016 11:44
@Amanieu
Copy link
Member Author

Amanieu commented Mar 19, 2016

Fixed.

Note that it seems atomic intrinsics currently don't work on non-integer types, this should be properly fixed at some point...

@alexcrichton
Copy link
Member

@bors: r+ 421fed1

@bors
Copy link
Contributor

bors commented Mar 19, 2016

⌛ Testing commit 421fed1 with merge 58ca226...

@bors
Copy link
Contributor

bors commented Mar 19, 2016

💔 Test failed - auto-win-msvc-64-opt-rustbuild

@alexcrichton
Copy link
Member

@bors: retry

On Sat, Mar 19, 2016 at 12:11 PM, bors [email protected] wrote:

[image: 💔] Test failed - auto-win-msvc-64-opt-rustbuild
http://buildbot.rust-lang.org/builders/auto-win-msvc-64-opt-rustbuild/builds/419


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
#32244 (comment)

@bors
Copy link
Contributor

bors commented Mar 19, 2016

⌛ Testing commit 421fed1 with merge 8eeb506...

bors added a commit that referenced this pull request Mar 19, 2016
Change compare_exchange to return a Result<T, T>

As per the discussion in #31767

I also changed the feature name from `extended_compare_and_swap` to `compare_exchange`.

r? @alexcrichton
@bors bors merged commit 421fed1 into rust-lang:master Mar 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants