Chromium Code Reviews| 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 "SkTypes.h" | |
| 14 | |
| 15 #include <utils/Atomic.h> | |
|
djsollen
2013/07/25 18:17:21
we should update this to
#include <cutils/atomic.
bungeman-skia
2013/09/26 17:16:23
Done.
| |
| 16 | |
| 17 #define sk_atomic_inc(addr) android_atomic_inc(addr) | |
| 18 #define sk_atomic_add(addr, inc) android_atomic_add(inc, addr) | |
| 19 #define sk_atomic_dec(addr) android_atomic_dec(addr) | |
| 20 | |
| 21 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi c_dec() { | |
| 22 //HACK: Android is actually using full memory barriers. | |
| 23 // Should this change, uncomment below. | |
| 24 //int dummy; | |
| 25 //android_atomic_acquire_store(0, &dummy); | |
| 26 } | |
| 27 | |
| 28 static inline __attribute__((always_inline)) int32_t sk_atomic_conditional_inc(i nt32_t* addr) { | |
| 29 while (true) { | |
| 30 int32_t value = *addr; | |
| 31 if (value == 0) { | |
| 32 return 0; | |
| 33 } | |
| 34 if (0 == android_atomic_release_cas(value, value + 1, addr)) { | |
| 35 return value; | |
| 36 } | |
| 37 } | |
| 38 } | |
| 39 | |
| 40 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi c_conditional_inc() { | |
| 41 //HACK: Android is actually using full memory barriers. | |
| 42 // Should this change, uncomment below. | |
| 43 //int dummy; | |
| 44 //android_atomic_acquire_store(0, &dummy); | |
| 45 } | |
| 46 | |
| 47 #endif | |
| OLD | NEW |