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

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

Issue 1441773002: SkAtomic: always use std::atomic (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 1 month 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
(Empty)
1 /*
2 * Copyright 2015 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef SkAtomics_std_DEFINED
9 #define SkAtomics_std_DEFINED
10
11 // We try not to depend on the C++ standard library,
12 // but these uses of <atomic> should all inline, so we don't feel to bad here.
13 #include <atomic>
14
15 template <typename T>
16 T sk_atomic_load(const T* ptr, sk_memory_order mo) {
17 SkASSERT(mo == sk_memory_order_relaxed ||
18 mo == sk_memory_order_seq_cst ||
19 mo == sk_memory_order_acquire ||
20 mo == sk_memory_order_consume);
21 const std::atomic<T>* ap = reinterpret_cast<const std::atomic<T>*>(ptr);
22 return std::atomic_load_explicit(ap, (std::memory_order)mo);
23 }
24
25 template <typename T>
26 void sk_atomic_store(T* ptr, T val, sk_memory_order mo) {
27 SkASSERT(mo == sk_memory_order_relaxed ||
28 mo == sk_memory_order_seq_cst ||
29 mo == sk_memory_order_release);
30 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
31 return std::atomic_store_explicit(ap, val, (std::memory_order)mo);
32 }
33
34 template <typename T>
35 T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) {
36 // All values of mo are valid.
37 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
38 return std::atomic_fetch_add_explicit(ap, val, (std::memory_order)mo);
39 }
40
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>
49 bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired,
50 sk_memory_order success,
51 sk_memory_order failure) {
52 // All values of success are valid.
53 SkASSERT(failure == sk_memory_order_relaxed ||
54 failure == sk_memory_order_seq_cst ||
55 failure == sk_memory_order_acquire ||
56 failure == sk_memory_order_consume);
57 SkASSERT(failure <= success);
58 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
59 return std::atomic_compare_exchange_strong_explicit(ap, expected, desired,
60 (std::memory_order)succe ss,
61 (std::memory_order)failu re);
62 }
63
64 template <typename T>
65 T sk_atomic_exchange(T* ptr, T val, sk_memory_order mo) {
66 // All values of mo are valid.
67 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
68 return std::atomic_exchange_explicit(ap, val, (std::memory_order)mo);
69 }
70
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