Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1705)

Side by Side Diff: src/ports/SkAtomics_win.h

Issue 377073002: Add support for 64bit atomics (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Use function versions on windows Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/ports/SkAtomics_sync.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 //MSDN says in order to declare an interlocked function for use as an 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 17 //intrinsic, include intrin.h and put the function in a #pragma intrinsic
18 //directive. 18 //directive.
19 //The pragma appears to be unnecessary, but doesn't hurt. 19 //The pragma appears to be unnecessary, but doesn't hurt.
20 #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDe crement) 20 #pragma intrinsic(_InterlockedIncrement, _InterlockedExchangeAdd, _InterlockedDe crement)
21 #pragma intrinsic(_InterlockedCompareExchange) 21 #pragma intrinsic(_InterlockedCompareExchange)
22 22
23 static inline int32_t sk_atomic_inc(int32_t* addr) { 23 static inline int32_t sk_atomic_inc(int32_t* addr) {
24 // InterlockedIncrement returns the new value, we want to return the old. 24 // InterlockedIncrement returns the new value, we want to return the old.
25 return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1; 25 return _InterlockedIncrement(reinterpret_cast<long*>(addr)) - 1;
26 } 26 }
27 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
28 static inline int32_t sk_atomic_add(int32_t* addr, int32_t inc) { 33 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)); 34 return _InterlockedExchangeAdd(reinterpret_cast<long*>(addr), static_cast<lo ng>(inc));
30 } 35 }
31 36
37 static inline int64_t sk_atomic_add(int64_t* addr, int64_t inc) {
38 return InterlockedExchangeAdd64(addr, inc);
39 }
40
32 static inline int32_t sk_atomic_dec(int32_t* addr) { 41 static inline int32_t sk_atomic_dec(int32_t* addr) {
33 // InterlockedDecrement returns the new value, we want to return the old. 42 // InterlockedDecrement returns the new value, we want to return the old.
34 return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1; 43 return _InterlockedDecrement(reinterpret_cast<long*>(addr)) + 1;
35 } 44 }
36 45
46 static inline int64_t sk_atomic_dec(int64_t* addr) {
47 // InterlockedDecrement returns the new value, we want to return the old.
48 return InterlockedDecrement64(addr) + 1;
49 }
50
37 static inline void sk_membar_acquire__after_atomic_dec() { } 51 static inline void sk_membar_acquire__after_atomic_dec() { }
38 52
39 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) { 53 static inline bool sk_atomic_cas(int32_t* addr, int32_t before, int32_t after) {
40 return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, bef ore) == before; 54 return _InterlockedCompareExchange(reinterpret_cast<long*>(addr), after, bef ore) == before;
41 } 55 }
42 56
57 static inline bool sk_atomic_cas(int64_t* addr, int64_t before, int64_t after) {
58 return _InterlockedCompareExchange64(addr, after, before) == before;
59 }
60
43 static inline void* sk_atomic_cas(void** addr, void* before, void* after) { 61 static inline void* sk_atomic_cas(void** addr, void* before, void* after) {
44 return InterlockedCompareExchangePointer(addr, after, before); 62 return InterlockedCompareExchangePointer(addr, after, before);
45 } 63 }
46 64
47 static inline void sk_membar_acquire__after_atomic_conditional_inc() { } 65 static inline void sk_membar_acquire__after_atomic_conditional_inc() { }
48 66
49 #endif 67 #endif
OLDNEW
« no previous file with comments | « src/ports/SkAtomics_sync.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698