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

Side by Side Diff: include/ports/SkAtomics_std.h

Issue 1348113004: Add subtract to atomics. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 3 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 | « include/ports/SkAtomics_atomic.h ('k') | include/ports/SkAtomics_sync.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_std_DEFINED 8 #ifndef SkAtomics_std_DEFINED
9 #define SkAtomics_std_DEFINED 9 #define SkAtomics_std_DEFINED
10 10
(...skipping 21 matching lines...) Expand all
32 } 32 }
33 33
34 template <typename T> 34 template <typename T>
35 T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) { 35 T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) {
36 // All values of mo are valid. 36 // All values of mo are valid.
37 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); 37 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
38 return std::atomic_fetch_add_explicit(ap, val, (std::memory_order)mo); 38 return std::atomic_fetch_add_explicit(ap, val, (std::memory_order)mo);
39 } 39 }
40 40
41 template <typename T> 41 template <typename T>
42 T sk_atomic_fetch_sub(T* ptr, T val, sk_memory_order mo) {
43 // All values of mo are valid.
44 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
45 return std::atomic_fetch_sub_explicit(ap, val, (std::memory_order)mo);
46 }
47
48 template <typename T>
42 bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, 49 bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired,
43 sk_memory_order success, 50 sk_memory_order success,
44 sk_memory_order failure) { 51 sk_memory_order failure) {
45 // All values of success are valid. 52 // All values of success are valid.
46 SkASSERT(failure == sk_memory_order_relaxed || 53 SkASSERT(failure == sk_memory_order_relaxed ||
47 failure == sk_memory_order_seq_cst || 54 failure == sk_memory_order_seq_cst ||
48 failure == sk_memory_order_acquire || 55 failure == sk_memory_order_acquire ||
49 failure == sk_memory_order_consume); 56 failure == sk_memory_order_consume);
50 SkASSERT(failure <= success); 57 SkASSERT(failure <= success);
51 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); 58 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
52 return std::atomic_compare_exchange_strong_explicit(ap, expected, desired, 59 return std::atomic_compare_exchange_strong_explicit(ap, expected, desired,
53 (std::memory_order)succe ss, 60 (std::memory_order)succe ss,
54 (std::memory_order)failu re); 61 (std::memory_order)failu re);
55 } 62 }
56 63
57 template <typename T> 64 template <typename T>
58 T sk_atomic_exchange(T* ptr, T val, sk_memory_order mo) { 65 T sk_atomic_exchange(T* ptr, T val, sk_memory_order mo) {
59 // All values of mo are valid. 66 // All values of mo are valid.
60 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); 67 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
61 return std::atomic_exchange_explicit(ap, val, (std::memory_order)mo); 68 return std::atomic_exchange_explicit(ap, val, (std::memory_order)mo);
62 } 69 }
63 70
64 #endif//SkAtomics_std_DEFINED 71 #endif//SkAtomics_std_DEFINED
OLDNEW
« no previous file with comments | « include/ports/SkAtomics_atomic.h ('k') | include/ports/SkAtomics_sync.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698