Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkAtomics_win_DEFINED | 8 #ifndef SkAtomics_win_DEFINED |
| 9 #define SkAtomics_win_DEFINED | 9 #define SkAtomics_win_DEFINED |
| 10 | 10 |
| 11 /** Windows Interlocked atomics. */ | 11 /** Windows Interlocked atomics. */ |
| 12 | 12 |
| 13 #include <intrin.h> | 13 #include <intrin.h> |
| 14 #include <stdint.h> | 14 #include <stdint.h> |
| 15 | 15 |
| 16 #ifdef _MSC_VER | |
|
bungeman-skia
2014/03/14 14:50:37
Why are you using this file at all? Why not #defin
| |
| 16 //MSDN says in order to declare an interlocked function for use as an | 17 //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 //intrinsic, include intrin.h and put the function in a #pragma intrinsic |
| 18 //directive. | 19 //directive. |
| 19 //The pragma appears to be unnecessary, but doesn't hurt. | 20 //The pragma appears to be unnecessary, but doesn't hurt. |
| 20 #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDe crement) | 21 #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDe crement) |
| 21 #pragma intrinsic(_InterlockedCompareExchange) | 22 #pragma intrinsic(_InterlockedCompareExchange) |
| 23 #endif | |
| 22 | 24 |
| 23 static inline int32_t sk_atomic_inc(int32_t* addr) { | 25 static inline int32_t sk_atomic_inc(int32_t* addr) { |
| 24 // InterlockedIncrement returns the new value, we want to return the old. | 26 // InterlockedIncrement returns the new value, we want to return the old. |
| 25 return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1; | 27 return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1; |
| 26 } | 28 } |
| 27 | 29 |
| 28 static inline int32_t sk_atomic_add(int32_t* addr, int32_t inc) { | 30 static inline int32_t sk_atomic_add(int32_t* addr, int32_t inc) { |
| 29 return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<lo ng>(inc)); | 31 return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<lo ng>(inc)); |
| 30 } | 32 } |
| 31 | 33 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 53 } | 55 } |
| 54 } | 56 } |
| 55 | 57 |
| 56 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) { | 58 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) { |
| 57 return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, bef ore) == before; | 59 return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, bef ore) == before; |
| 58 } | 60 } |
| 59 | 61 |
| 60 static inline void sk_membar_acquire__after_atomic_conditional_inc() { } | 62 static inline void sk_membar_acquire__after_atomic_conditional_inc() { } |
| 61 | 63 |
| 62 #endif | 64 #endif |
| OLD | NEW |