OLD | NEW |
1 /* Copyright 2013 The Chromium Authors. All rights reserved. | 1 /* Copyright 2013 The Chromium Authors. All rights reserved. |
2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
4 */ | 4 */ |
5 | 5 |
6 #ifndef LIBRARIES_SDK_UTIL_ATOMICOPS_H_ | 6 #ifndef LIBRARIES_SDK_UTIL_ATOMICOPS_H_ |
7 #define LIBRARIES_SDK_UTIL_ATOMICOPS_H_ | 7 #define LIBRARIES_SDK_UTIL_ATOMICOPS_H_ |
8 | 8 |
9 #ifndef WIN32 | 9 #ifndef WIN32 |
10 | 10 |
11 #include <stdint.h> | 11 #include <stdint.h> |
| 12 |
| 13 namespace sdk_util { |
| 14 |
12 typedef int32_t Atomic32; | 15 typedef int32_t Atomic32; |
13 | 16 |
14 #ifndef __llvm__ | 17 #ifndef __llvm__ |
15 static inline void MemoryBarrier() { | 18 static inline void MemoryBarrier() { |
16 __sync_synchronize(); | 19 __sync_synchronize(); |
17 } | 20 } |
18 #endif | 21 #endif |
19 | 22 |
20 inline Atomic32 AtomicCompareExchange(volatile Atomic32* ptr, | 23 inline Atomic32 AtomicCompareExchange(volatile Atomic32* ptr, |
21 Atomic32 new_value, | 24 Atomic32 new_value, |
(...skipping 10 matching lines...) Expand all Loading... |
32 } | 35 } |
33 | 36 |
34 inline Atomic32 AtomicOrFetch(volatile Atomic32* ptr, Atomic32 value) { | 37 inline Atomic32 AtomicOrFetch(volatile Atomic32* ptr, Atomic32 value) { |
35 return __sync_or_and_fetch(ptr, value); | 38 return __sync_or_and_fetch(ptr, value); |
36 } | 39 } |
37 | 40 |
38 inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) { | 41 inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) { |
39 return __sync_xor_and_fetch(ptr, value); | 42 return __sync_xor_and_fetch(ptr, value); |
40 } | 43 } |
41 | 44 |
42 #else | 45 } // namespace sdk_util |
| 46 |
| 47 #else // ifndef WIN32 |
43 | 48 |
44 #include <windows.h> | 49 #include <windows.h> |
45 | 50 |
46 /* Undefine many Windows.h macros that we almost certainly do not want. */ | 51 /* Undefine many Windows.h macros that we almost certainly do not want. */ |
47 #undef min | 52 #undef min |
48 #undef max | 53 #undef max |
49 #undef PostMessage | 54 #undef PostMessage |
50 #undef interface | 55 #undef interface |
51 | 56 |
| 57 namespace sdk_util { |
| 58 |
52 typedef long Atomic32; | 59 typedef long Atomic32; |
53 | 60 |
54 /* Windows.h already defines a MemoryBarrier macro. */ | 61 /* Windows.h already defines a MemoryBarrier macro. */ |
55 | 62 |
56 inline Atomic32 AtomicCompareExchange(volatile Atomic32* ptr, | 63 inline Atomic32 AtomicCompareExchange(volatile Atomic32* ptr, |
57 Atomic32 newvalue, | 64 Atomic32 newvalue, |
58 Atomic32 oldvalue) { | 65 Atomic32 oldvalue) { |
59 return InterlockedCompareExchange(ptr, newvalue, oldvalue); | 66 return InterlockedCompareExchange(ptr, newvalue, oldvalue); |
60 } | 67 } |
61 | 68 |
(...skipping 27 matching lines...) Expand all Loading... |
89 Atomic32 oldval; | 96 Atomic32 oldval; |
90 Atomic32 newval; | 97 Atomic32 newval; |
91 do { | 98 do { |
92 oldval = *ptr; | 99 oldval = *ptr; |
93 newval = oldval ^ value; | 100 newval = oldval ^ value; |
94 } while (InterlockedCompareExchange(ptr,newval, oldval) != oldval); | 101 } while (InterlockedCompareExchange(ptr,newval, oldval) != oldval); |
95 | 102 |
96 return newval; | 103 return newval; |
97 } | 104 } |
98 | 105 |
99 #endif | 106 } // namespace sdk_util |
100 | 107 |
| 108 #endif // ifndef WIN32 |
101 | 109 |
102 #endif /* LIBRARIES_SDK_UTIL_ATOMICOPS_H_ */ | 110 #endif /* LIBRARIES_SDK_UTIL_ATOMICOPS_H_ */ |
OLD | NEW |