Skip to content

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

Merged
bors merged 1 commit into
rust-lang:masterfrom
Amanieu:compare_exchange_result
Mar 19, 2016
Merged

Change compare_exchange to return a Result<T, T>#32244
bors merged 1 commit into
rust-lang:masterfrom
Amanieu:compare_exchange_result

Conversation

@Amanieu

Copy link
Copy Markdown
Member

As per the discussion in #31767

I also changed the feature name from extended_compare_and_swap to compare_exchange.

r? @alexcrichton

@Amanieu
Amanieuforce-pushed the compare_exchange_result branch 2 times, most recently from d7e8302 to acb9256CompareMarch 14, 2016 13:48
@alexcrichton

Copy link
Copy Markdown
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)

@alexcrichtonalexcrichton added the T-libs-api [DEPRECATED; DO NOT USE] label Mar 14, 2016
@alexcrichton

Copy link
Copy Markdown
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?

@alexcrichtonalexcrichton removed the T-libs-api [DEPRECATED; DO NOT USE] label Mar 17, 2016
@Amanieu
Amanieuforce-pushed the compare_exchange_result branch 2 times, most recently from cb3e048 to 2964f18CompareMarch 17, 2016 23:40
@Amanieu

Copy link
Copy Markdown
MemberAuthor

Done

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+ 2964f1873e54b42cc3994ba8882d2486305c32c3

@bors

bors commented Mar 18, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 2964f18 with merge dedfe4a...

@bors

bors commented Mar 18, 2016

Copy link
Copy Markdown
Collaborator

💔 Test failed - auto-mac-64-opt

@Amanieu
Amanieuforce-pushed the compare_exchange_result branch from 2964f18 to 928d8cdCompareMarch 18, 2016 09:47
@Amanieu

Copy link
Copy Markdown
MemberAuthor

Fixed

@Amanieu
Amanieuforce-pushed the compare_exchange_result branch from 928d8cd to 18222c0CompareMarch 18, 2016 10:04
@eddyb

Copy link
Copy Markdown
Contributor

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

@bors

bors commented Mar 18, 2016

Copy link
Copy Markdown
Collaborator

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

@Amanieu
Amanieuforce-pushed the compare_exchange_result branch 3 times, most recently from 4187714 to 6f0a130CompareMarch 19, 2016 01:54
@Amanieu

Copy link
Copy Markdown
MemberAuthor

I think this should be fixed now

@alexcrichton

Copy link
Copy Markdown
Member

@bors: r+ 6f0a1307741e7d1d297aeffd2ec15eb905e1d487

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Collaborator

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

@alexcrichton

Copy link
Copy Markdown
Member

@bors: retry force clean

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Collaborator

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

@Amanieu
Amanieuforce-pushed the compare_exchange_result branch from 6f0a130 to 421fed1CompareMarch 19, 2016 11:44
@Amanieu

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
Member

@bors: r+ 421fed1

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Collaborator

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

@bors

bors commented Mar 19, 2016

Copy link
Copy Markdown
Collaborator

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

@alexcrichton

Copy link
Copy Markdown
Member

@bors: retry

On Sat, Mar 19, 2016 at 12:11 PM, bors notifications@github.com 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

bors commented Mar 19, 2016

Copy link
Copy Markdown
Collaborator

⌛ 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:masterMar 19, 2016
Sign up for freeto 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

@Amanieu@alexcrichton@bors@eddyb