Work around C11 const atomic restrictions.
Cast away the const qualifier in BBinder::findObject. C11, unlike C++11, does not allow loads from const atomics. This is widely regarded as a bug (see WG14 DR 459). This is a hack to work around it until it's officially fixed in the spec. load_const_atomic was adapted from commit 1e8587a479fd8b1ce9b594298a93f517816e8f15 I don't think we want to dignify this by putting it into a header file. Bug:17067219 Change-Id: Icbfcbda2722e6f80d2bb065a0bb3ec7634bcacb2
This commit is contained in:
parent
7d587c31d5
commit
c0df68bb80
|
@ -160,10 +160,18 @@ void BBinder::attachObject(
|
|||
e->mObjects.attach(objectID, object, cleanupCookie, func);
|
||||
}
|
||||
|
||||
// The C11 standard doesn't allow atomic loads from const fields,
|
||||
// though C++11 does. Fudge it until standards get straightened out.
|
||||
static inline uintptr_t load_const_atomic(const atomic_uintptr_t* p,
|
||||
memory_order mo) {
|
||||
atomic_uintptr_t* non_const_p = const_cast<atomic_uintptr_t*>(p);
|
||||
return atomic_load_explicit(non_const_p, mo);
|
||||
}
|
||||
|
||||
void* BBinder::findObject(const void* objectID) const
|
||||
{
|
||||
Extras* e = reinterpret_cast<Extras*>(
|
||||
atomic_load_explicit(&mExtras, memory_order_acquire));
|
||||
load_const_atomic(&mExtras, memory_order_acquire));
|
||||
if (!e) return NULL;
|
||||
|
||||
AutoMutex _l(e->mLock);
|
||||
|
|
Loading…
Reference in New Issue