| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkAtomics_android_DEFINED | 8 #ifndef SkAtomics_android_DEFINED |
| 9 #define SkAtomics_android_DEFINED | 9 #define SkAtomics_android_DEFINED |
| 10 | 10 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 return android_atomic_dec(addr); | 25 return android_atomic_dec(addr); |
| 26 } | 26 } |
| 27 | 27 |
| 28 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_dec() { | 28 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_dec() { |
| 29 //HACK: Android is actually using full memory barriers. | 29 //HACK: Android is actually using full memory barriers. |
| 30 // Should this change, uncomment below. | 30 // Should this change, uncomment below. |
| 31 //int dummy; | 31 //int dummy; |
| 32 //android_atomic_acquire_store(0, &dummy); | 32 //android_atomic_acquire_store(0, &dummy); |
| 33 } | 33 } |
| 34 | 34 |
| 35 static inline __attribute__((always_inline)) int32_t sk_atomic_conditional_inc(i
nt32_t* addr) { | |
| 36 while (true) { | |
| 37 int32_t value = *addr; | |
| 38 if (value == 0) { | |
| 39 return 0; | |
| 40 } | |
| 41 if (0 == android_atomic_release_cas(value, value + 1, addr)) { | |
| 42 return value; | |
| 43 } | |
| 44 } | |
| 45 } | |
| 46 | |
| 47 static inline __attribute__((always_inline)) bool sk_atomic_cas(int32_t* addr, | 35 static inline __attribute__((always_inline)) bool sk_atomic_cas(int32_t* addr, |
| 48 int32_t before, | 36 int32_t before, |
| 49 int32_t after)
{ | 37 int32_t after)
{ |
| 50 // android_atomic_release_cas returns 0 for success (if *addr == before and
it wrote after). | 38 // android_atomic_release_cas returns 0 for success (if *addr == before and
it wrote after). |
| 51 return android_atomic_release_cas(before, after, addr) == 0; | 39 return android_atomic_release_cas(before, after, addr) == 0; |
| 52 } | 40 } |
| 53 | 41 |
| 54 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_conditional_inc() { | 42 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_conditional_inc() { |
| 55 //HACK: Android is actually using full memory barriers. | 43 //HACK: Android is actually using full memory barriers. |
| 56 // Should this change, uncomment below. | 44 // Should this change, uncomment below. |
| 57 //int dummy; | 45 //int dummy; |
| 58 //android_atomic_acquire_store(0, &dummy); | 46 //android_atomic_acquire_store(0, &dummy); |
| 59 } | 47 } |
| 60 | 48 |
| 61 #endif | 49 #endif |
| OLD | NEW |