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 static inline __attribute__((always_inline)) int32_t sk_atomic_inc(int32_t* addr
) { | |
17 return android_atomic_inc(addr); | |
18 } | |
19 | |
20 static inline __attribute__((always_inline)) int32_t sk_atomic_add(int32_t* addr
, int32_t inc) { | |
21 return android_atomic_add(inc, addr); | |
22 } | |
23 | |
24 static inline __attribute__((always_inline)) int32_t sk_atomic_dec(int32_t* addr
) { | |
25 return android_atomic_dec(addr); | |
26 } | |
27 | |
28 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_dec() { | |
29 //HACK: Android is actually using full memory barriers. | |
30 // Should this change, uncomment below. | |
31 //int dummy; | |
32 //android_atomic_acquire_store(0, &dummy); | |
33 } | |
34 | |
35 static inline __attribute__((always_inline)) bool sk_atomic_cas(int32_t* addr, | |
36 int32_t before, | |
37 int32_t after)
{ | |
38 // android_atomic_release_cas returns 0 for success (if *addr == before and
it wrote after). | |
39 return android_atomic_release_cas(before, after, addr) == 0; | |
40 } | |
41 | |
42 static inline __attribute__((always_inline)) void sk_membar_acquire__after_atomi
c_conditional_inc() { | |
43 //HACK: Android is actually using full memory barriers. | |
44 // Should this change, uncomment below. | |
45 //int dummy; | |
46 //android_atomic_acquire_store(0, &dummy); | |
47 } | |
48 | |
49 #endif | |
OLD | NEW |