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 18 matching lines...) Expand all Loading... |
29 int32_t value = *addr; | 29 int32_t value = *addr; |
30 if (value == 0) { | 30 if (value == 0) { |
31 return 0; | 31 return 0; |
32 } | 32 } |
33 if (0 == android_atomic_release_cas(value, value + 1, addr)) { | 33 if (0 == android_atomic_release_cas(value, value + 1, addr)) { |
34 return value; | 34 return value; |
35 } | 35 } |
36 } | 36 } |
37 } | 37 } |
38 | 38 |
| 39 static inline __attribute___((always_inline)) bool sk_atomic_cas(int32_t* addr, |
| 40 int32_t before, |
| 41 int32_t after)
{ |
| 42 // android_atomic_release_cas returns 0 for success (if *addr == before and
it wrote after). |
| 43 return android_atomic_release_cas(before, after, addr) == 0; |
| 44 } |
| 45 |
39 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_conditional_inc() { | 46 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_conditional_inc() { |
40 //HACK: Android is actually using full memory barriers. | 47 //HACK: Android is actually using full memory barriers. |
41 // Should this change, uncomment below. | 48 // Should this change, uncomment below. |
42 //int dummy; | 49 //int dummy; |
43 //android_atomic_acquire_store(0, &dummy); | 50 //android_atomic_acquire_store(0, &dummy); |
44 } | 51 } |
45 | 52 |
46 #endif | 53 #endif |
OLD | NEW |