Chromium Code Reviews| 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 typedef int32_t Atomic32; | 12 typedef int32_t Atomic32; |
| 13 | 13 |
| 14 #ifndef __llvm__ | 14 #ifndef __llvm__ |
| 15 static inline void MemoryBarrier() { | 15 static inline void MemoryBarrier() { |
| 16 __sync_synchronize(); | 16 __sync_synchronize(); |
| 17 } | 17 } |
| 18 #endif | 18 #endif |
| 19 | 19 |
| 20 inline Atomic32 AtomicAddFetch(volatile Atomic32* ptr, Atomic32 value) { | 20 inline Atomic32 AtomicAddFetch(volatile Atomic32* ptr, Atomic32 value) { |
| 21 return __sync_add_and_fetch(ptr, value); | 21 return __sync_add_and_fetch(ptr, value); |
| 22 } | 22 } |
| 23 | 23 |
| 24 inline Atomic32 AtomicAndFetch(volatile Atomic32* ptr, Atomic32 value) { | |
|
binji
2013/07/12 00:51:23
these are not used, maybe add them in a CL that us
noelallen1
2013/07/12 23:18:47
I though it made more sense to break them out with
| |
| 25 return __sync_and_and_fetch(ptr, value); | |
| 26 } | |
| 27 | |
| 28 inline Atomic32 AtomicOrFetch(volatile Atomic32* ptr, Atomic32 value) { | |
| 29 return __sync_or_and_fetch(ptr, value); | |
| 30 } | |
| 31 | |
| 32 inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) { | |
| 33 return __sync_xor_and_fetch(ptr, value); | |
| 34 } | |
| 35 | |
| 24 #else | 36 #else |
| 25 | 37 |
| 26 #include <windows.h> | 38 #include <windows.h> |
| 27 | 39 |
| 28 /* Undefine many Windows.h macros that we almost certainly do not want. */ | 40 /* Undefine many Windows.h macros that we almost certainly do not want. */ |
| 29 #undef min | 41 #undef min |
| 30 #undef max | 42 #undef max |
| 31 #undef PostMessage | 43 #undef PostMessage |
| 32 #undef interface | 44 #undef interface |
| 33 | 45 |
| 34 typedef long Atomic32; | 46 typedef long Atomic32; |
| 35 | 47 |
| 36 /* Windows.h already defines a MemoryBarrier macro. */ | 48 /* Windows.h already defines a MemoryBarrier macro. */ |
| 37 | 49 |
| 38 inline Atomic32 AtomicAddFetch(volatile Atomic32* ptr, Atomic32 value) { | 50 inline Atomic32 AtomicAddFetch(volatile Atomic32* ptr, Atomic32 value) { |
| 39 return InterlockedExchangeAdd(ptr, value); | 51 return InterlockedExchangeAdd(ptr, value); |
| 40 } | 52 } |
| 53 | |
| 54 inline Atomic32 AtomicAndFetch(volatile Atomic32* ptr, Atomic32 value) { | |
| 55 return InterlockedAnd(ptr, value); | |
| 56 } | |
| 57 | |
| 58 inline Atomic32 AtomicOrFetch(volatile Atomic32* ptr, Atomic32 value) { | |
| 59 return InterlockedOr(ptr, value); | |
| 60 } | |
| 61 | |
| 62 inline Atomic32 AtomicXorFetch(volatile Atomic32* ptr, Atomic32 value) { | |
| 63 return InterlockedOr(ptr, value); | |
| 64 } | |
| 65 | |
| 41 #endif | 66 #endif |
| 42 | 67 |
| 43 | 68 |
| 44 #endif /* LIBRARIES_SDK_UTIL_ATOMICOPS_H_ */ | 69 #endif /* LIBRARIES_SDK_UTIL_ATOMICOPS_H_ */ |
| OLD | NEW |