Mir

Merge lp:~alan-griffiths/mir/use-compare_exchange_weak-correctly into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: no longer in the source branch.
Merged at revision: 1950
Proposed branch: lp:~alan-griffiths/mir/use-compare_exchange_weak-correctly
Merge into: lp:mir
Diff against target: 24 lines (+2/-2)
2 files modified
3rd_party/android-deps/std/atomic.h (+1/-1)
src/include/common/mir/basic_observers.h (+1/-1)
To merge this branch: bzr merge lp:~alan-griffiths/mir/use-compare_exchange_weak-correctly
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
Daniel van Vugt Needs Information
Alberto Aguirre (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+236557@code.launchpad.net

Commit message

common: correct usage of compare_exchange_weak()

Description of the change

common: correct usage of compare_exchange_weak()

compare_exchange_weak() is allowed to "fail spuriously". That is, it may act as if *this != expected even if they are equal. This would cause it to return false and the expected-variable to be unaltered, leading, e.g. to null pointer access in BasicObservers<Observer>::add().

(This may well not apply to our platform, but I'm correcting the code anyway.)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

Oh yeah!

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

(1) 3rd_party/android-deps/std/atomic.h: I think it's probably a better idea to not fix 3rd party code when there is nothing provably wrong with the current form (yet). We should assume Google's using it in a way that is safe until proven otherwise. Or is it definitely not safe right now?

Happy for our own code to get fixes though...

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> (1) 3rd_party/android-deps/std/atomic.h: I think it's probably a better idea
> to not fix 3rd party code when there is nothing provably wrong with the
> current form (yet). We should assume Google's using it in a way that is safe
> until proven otherwise. Or is it definitely not safe right now?

1.1. The code is ours (.../std/... is a re-implementation using the standard library to replace android code).

1.2. It is wrong for the reasons described in the MP (it doesn't correctly handle spurious failures).

Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '3rd_party/android-deps/std/atomic.h'
2--- 3rd_party/android-deps/std/atomic.h 2013-03-13 04:54:15 +0000
3+++ 3rd_party/android-deps/std/atomic.h 2014-09-30 16:10:51 +0000
4@@ -80,7 +80,7 @@
5 //int android_atomic_acquire_cas(int32_t oldvalue, int32_t newvalue,
6 // volatile int32_t* addr);
7 inline int android_atomic_release_cas(int32_t oldvalue, int32_t newvalue,
8- android_atomic_int32_t* addr) { return !addr->compare_exchange_weak(oldvalue, newvalue); }
9+ android_atomic_int32_t* addr) { return !addr->compare_exchange_strong(oldvalue, newvalue); }
10 }
11
12 /*
13
14=== modified file 'src/include/common/mir/basic_observers.h'
15--- src/include/common/mir/basic_observers.h 2014-09-11 05:51:44 +0000
16+++ src/include/common/mir/basic_observers.h 2014-09-30 16:10:51 +0000
17@@ -95,7 +95,7 @@
18 !current_item->next.compare_exchange_weak(expected, new_item);
19 expected = nullptr)
20 {
21- current_item = expected;
22+ if (expected) current_item = expected;
23 }
24 }
25

Subscribers

People subscribed via source and target branches