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 |
(...skipping 18 matching lines...) Expand all Loading... |
29 return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<lo
ng>(inc)); | 29 return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<lo
ng>(inc)); |
30 } | 30 } |
31 | 31 |
32 static inline int32_t sk_atomic_dec(int32_t* addr) { | 32 static inline int32_t sk_atomic_dec(int32_t* addr) { |
33 // InterlockedDecrement returns the new value, we want to return the old. | 33 // InterlockedDecrement returns the new value, we want to return the old. |
34 return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1; | 34 return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1; |
35 } | 35 } |
36 | 36 |
37 static inline void sk_membar_acquire__after_atomic_dec() { } | 37 static inline void sk_membar_acquire__after_atomic_dec() { } |
38 | 38 |
39 static inline int32_t sk_atomic_conditional_inc(int32_t* addr) { | |
40 long value = *addr; | |
41 while (true) { | |
42 if (value == 0) { | |
43 return 0; | |
44 } | |
45 | |
46 long before = _InterlockedCompareExchange(reinterpret_cast<long*>(addr),
value + 1, value); | |
47 | |
48 if (before == value) { | |
49 return value; | |
50 } else { | |
51 value = before; | |
52 } | |
53 } | |
54 } | |
55 | |
56 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) { | 39 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; | 40 return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, bef
ore) == before; |
58 } | 41 } |
59 | 42 |
60 static inline void sk_membar_acquire__after_atomic_conditional_inc() { } | 43 static inline void sk_membar_acquire__after_atomic_conditional_inc() { } |
61 | 44 |
62 #endif | 45 #endif |
OLD | NEW |