OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright 2013 Google Inc. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. |
| 6 */ |
| 7 |
| 8 #ifndef SkAtomics_android_DEFINED |
| 9 #define SkAtomics_android_DEFINED |
| 10 |
| 11 /** Android framework atomics. */ |
| 12 |
| 13 #include <cutils/atomic.h> |
| 14 #include <stdint.h> |
| 15 |
| 16 #define sk_atomic_inc(addr) android_atomic_inc(addr) |
| 17 #define sk_atomic_add(addr, inc) android_atomic_add(inc, addr) |
| 18 #define sk_atomic_dec(addr) android_atomic_dec(addr) |
| 19 |
| 20 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_dec() { |
| 21 //HACK: Android is actually using full memory barriers. |
| 22 // Should this change, uncomment below. |
| 23 //int dummy; |
| 24 //android_atomic_acquire_store(0, &dummy); |
| 25 } |
| 26 |
| 27 static inline __attribute__((always_inline)) int32_t sk_atomic_conditional_inc(i
nt32_t* addr) { |
| 28 while (true) { |
| 29 int32_t value = *addr; |
| 30 if (value == 0) { |
| 31 return 0; |
| 32 } |
| 33 if (0 == android_atomic_release_cas(value, value + 1, addr)) { |
| 34 return value; |
| 35 } |
| 36 } |
| 37 } |
| 38 |
| 39 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_conditional_inc() { |
| 40 //HACK: Android is actually using full memory barriers. |
| 41 // Should this change, uncomment below. |
| 42 //int dummy; |
| 43 //android_atomic_acquire_store(0, &dummy); |
| 44 } |
| 45 |
| 46 #endif |
OLD | NEW |