OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2007, 2008, 2010, 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2007, 2008, 2010, 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) | 3 * Copyright (C) 2007 Justin Haygood (jhaygood@reaktix.com) |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * | 8 * |
9 * 1. Redistributions of source code must retain the above copyright | 9 * 1. Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 15 matching lines...) Expand all Loading... |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 */ | 28 */ |
29 | 29 |
30 #ifndef Atomics_h | 30 #ifndef Atomics_h |
31 #define Atomics_h | 31 #define Atomics_h |
32 | 32 |
33 #include "wtf/CPU.h" | 33 #include "wtf/CPU.h" |
34 #include <stdint.h> | 34 #include <stdint.h> |
35 | 35 |
36 #if OS(WINDOWS) | 36 #if OS(WIN) |
37 #include <windows.h> | 37 #include <windows.h> |
38 #elif OS(ANDROID) | 38 #elif OS(ANDROID) |
39 #include <sys/atomics.h> | 39 #include <sys/atomics.h> |
40 #endif | 40 #endif |
41 | 41 |
42 namespace WTF { | 42 namespace WTF { |
43 | 43 |
44 #if OS(WINDOWS) | 44 #if OS(WIN) |
45 | 45 |
46 ALWAYS_INLINE int atomicIncrement(int volatile* addend) { return InterlockedIncr
ement(reinterpret_cast<long volatile*>(addend)); } | 46 ALWAYS_INLINE int atomicIncrement(int volatile* addend) { return InterlockedIncr
ement(reinterpret_cast<long volatile*>(addend)); } |
47 ALWAYS_INLINE int atomicDecrement(int volatile* addend) { return InterlockedDecr
ement(reinterpret_cast<long volatile*>(addend)); } | 47 ALWAYS_INLINE int atomicDecrement(int volatile* addend) { return InterlockedDecr
ement(reinterpret_cast<long volatile*>(addend)); } |
48 | 48 |
49 ALWAYS_INLINE int64_t atomicIncrement(int64_t volatile* addend) { return Interlo
ckedIncrement64(reinterpret_cast<long long volatile*>(addend)); } | 49 ALWAYS_INLINE int64_t atomicIncrement(int64_t volatile* addend) { return Interlo
ckedIncrement64(reinterpret_cast<long long volatile*>(addend)); } |
50 ALWAYS_INLINE int64_t atomicDecrement(int64_t volatile* addend) { return Interlo
ckedDecrement64(reinterpret_cast<long long volatile*>(addend)); } | 50 ALWAYS_INLINE int64_t atomicDecrement(int64_t volatile* addend) { return Interlo
ckedDecrement64(reinterpret_cast<long long volatile*>(addend)); } |
51 | 51 |
52 #elif OS(ANDROID) | 52 #elif OS(ANDROID) |
53 | 53 |
54 // Note, __atomic_{inc, dec}() return the previous value of addend's content. | 54 // Note, __atomic_{inc, dec}() return the previous value of addend's content. |
55 ALWAYS_INLINE int atomicIncrement(int volatile* addend) { return __atomic_inc(ad
dend) + 1; } | 55 ALWAYS_INLINE int atomicIncrement(int volatile* addend) { return __atomic_inc(ad
dend) + 1; } |
56 ALWAYS_INLINE int atomicDecrement(int volatile* addend) { return __atomic_dec(ad
dend) - 1; } | 56 ALWAYS_INLINE int atomicDecrement(int volatile* addend) { return __atomic_dec(ad
dend) - 1; } |
57 | 57 |
58 #else | 58 #else |
59 | 59 |
60 ALWAYS_INLINE int atomicIncrement(int volatile* addend) { return __sync_add_and_
fetch(addend, 1); } | 60 ALWAYS_INLINE int atomicIncrement(int volatile* addend) { return __sync_add_and_
fetch(addend, 1); } |
61 ALWAYS_INLINE int atomicDecrement(int volatile* addend) { return __sync_sub_and_
fetch(addend, 1); } | 61 ALWAYS_INLINE int atomicDecrement(int volatile* addend) { return __sync_sub_and_
fetch(addend, 1); } |
62 | 62 |
63 ALWAYS_INLINE int64_t atomicIncrement(int64_t volatile* addend) { return __sync_
add_and_fetch(addend, 1); } | 63 ALWAYS_INLINE int64_t atomicIncrement(int64_t volatile* addend) { return __sync_
add_and_fetch(addend, 1); } |
64 ALWAYS_INLINE int64_t atomicDecrement(int64_t volatile* addend) { return __sync_
sub_and_fetch(addend, 1); } | 64 ALWAYS_INLINE int64_t atomicDecrement(int64_t volatile* addend) { return __sync_
sub_and_fetch(addend, 1); } |
65 | 65 |
66 #endif | 66 #endif |
67 | 67 |
68 } // namespace WTF | 68 } // namespace WTF |
69 | 69 |
70 using WTF::atomicDecrement; | 70 using WTF::atomicDecrement; |
71 using WTF::atomicIncrement; | 71 using WTF::atomicIncrement; |
72 | 72 |
73 #endif // Atomics_h | 73 #endif // Atomics_h |
OLD | NEW |