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

Side by Side Diff: include/core/SkAtomics.h

Issue 1193493003: Modernize atomics in SkTaskGroup's threadpool. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 6 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 | « no previous file | src/core/SkTaskGroup.h » ('j') | 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 2015 Google Inc. 2 * Copyright 2015 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_DEFINED 8 #ifndef SkAtomics_DEFINED
9 #define SkAtomics_DEFINED 9 #define SkAtomics_DEFINED
10 10
(...skipping 25 matching lines...) Expand all
36 36
37 template <typename T> 37 template <typename T>
38 T sk_atomic_exchange(T*, T, sk_memory_order = sk_memory_order_seq_cst); 38 T sk_atomic_exchange(T*, T, sk_memory_order = sk_memory_order_seq_cst);
39 39
40 // A little wrapper class for small T (think, builtins: int, float, void*) to 40 // A little wrapper class for small T (think, builtins: int, float, void*) to
41 // ensure they're always used atomically. This is our stand-in for std::atomic< T>. 41 // ensure they're always used atomically. This is our stand-in for std::atomic< T>.
42 template <typename T> 42 template <typename T>
43 class SkAtomic : SkNoncopyable { 43 class SkAtomic : SkNoncopyable {
44 public: 44 public:
45 SkAtomic() {} 45 SkAtomic() {}
46 explicit SkAtomic(const T& val) : fVal(val) {}
46 47
47 // It is essential we return by value rather than by const&. fVal may chang e at any time. 48 // It is essential we return by value rather than by const&. fVal may chang e at any time.
48 T load(sk_memory_order mo = sk_memory_order_seq_cst) const { 49 T load(sk_memory_order mo = sk_memory_order_seq_cst) const {
49 return sk_atomic_load(&fVal, mo); 50 return sk_atomic_load(&fVal, mo);
50 } 51 }
51 52
52 void store(const T& val, sk_memory_order mo = sk_memory_order_seq_cst) { 53 void store(const T& val, sk_memory_order mo = sk_memory_order_seq_cst) {
53 sk_atomic_store(&fVal, val, mo); 54 sk_atomic_store(&fVal, val, mo);
54 } 55 }
55 56
57 T fetch_add(const T& val, sk_memory_order mo = sk_memory_order_seq_cst) {
58 return sk_atomic_fetch_add(&fVal, val, mo);
59 }
60
56 bool compare_exchange(T* expected, const T& desired, 61 bool compare_exchange(T* expected, const T& desired,
57 sk_memory_order success = sk_memory_order_seq_cst, 62 sk_memory_order success = sk_memory_order_seq_cst,
58 sk_memory_order failure = sk_memory_order_seq_cst) { 63 sk_memory_order failure = sk_memory_order_seq_cst) {
59 return sk_atomic_compare_exchange(&fVal, expected, desired, success, fai lure); 64 return sk_atomic_compare_exchange(&fVal, expected, desired, success, fai lure);
60 } 65 }
61 private: 66 private:
62 T fVal; 67 T fVal;
63 }; 68 };
64 69
65 #if defined(_MSC_VER) 70 #if defined(_MSC_VER)
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 template <typename T> 107 template <typename T>
103 T sk_acquire_load(T* ptr) { return sk_atomic_load(ptr, sk_memory_order_acquire); } 108 T sk_acquire_load(T* ptr) { return sk_atomic_load(ptr, sk_memory_order_acquire); }
104 109
105 template <typename T> 110 template <typename T>
106 void sk_release_store(T* ptr, T val) { sk_atomic_store(ptr, val, sk_memory_order _release); } 111 void sk_release_store(T* ptr, T val) { sk_atomic_store(ptr, val, sk_memory_order _release); }
107 112
108 inline void sk_membar_acquire__after_atomic_dec() {} 113 inline void sk_membar_acquire__after_atomic_dec() {}
109 inline void sk_membar_acquire__after_atomic_conditional_inc() {} 114 inline void sk_membar_acquire__after_atomic_conditional_inc() {}
110 115
111 #endif//SkAtomics_DEFINED 116 #endif//SkAtomics_DEFINED
OLDNEW
« no previous file with comments | « no previous file | src/core/SkTaskGroup.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698