| 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_win_DEFINED | |
| 9 #define SkAtomics_win_DEFINED | |
| 10 | |
| 11 /** Windows Interlocked atomics. */ | |
| 12 | |
| 13 #include <intrin.h> | |
| 14 #include <stdint.h> | |
| 15 | |
| 16 //MSDN says in order to declare an interlocked function for use as an | |
| 17 //intrinsic, include intrin.h and put the function in a #pragma intrinsic | |
| 18 //directive. | |
| 19 //The pragma appears to be unnecessary, but doesn't hurt. | |
| 20 #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDe
crement) | |
| 21 #pragma intrinsic(_InterlockedCompareExchange) | |
| 22 | |
| 23 static inline int32_t sk_atomic_inc(int32_t* addr) { | |
| 24 // InterlockedIncrement returns the new value, we want to return the old. | |
| 25 return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1; | |
| 26 } | |
| 27 | |
| 28 static inline int64_t sk_atomic_inc(int64_t* addr) { | |
| 29 // InterlockedIncrement returns the new value, we want to return the old. | |
| 30 return InterlockedIncrement64(addr) - 1; | |
| 31 } | |
| 32 | |
| 33 static inline int32_t sk_atomic_add(int32_t* addr, int32_t inc) { | |
| 34 return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<lo
ng>(inc)); | |
| 35 } | |
| 36 | |
| 37 static inline int32_t sk_atomic_dec(int32_t* addr) { | |
| 38 // InterlockedDecrement returns the new value, we want to return the old. | |
| 39 return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1; | |
| 40 } | |
| 41 | |
| 42 static inline void sk_membar_acquire__after_atomic_dec() { } | |
| 43 | |
| 44 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) { | |
| 45 return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, bef
ore) == before; | |
| 46 } | |
| 47 | |
| 48 static inline void* sk_atomic_cas(void** addr, void* before, void* after) { | |
| 49 return InterlockedCompareExchangePointer(addr, after, before); | |
| 50 } | |
| 51 | |
| 52 static inline void sk_membar_acquire__after_atomic_conditional_inc() { } | |
| 53 | |
| 54 #endif | |
| OLD | NEW |