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

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

Issue 1039323002: Extract the spinlock from SkOnce as SkSpinlock. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: quotes Created 5 years, 9 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
OLDNEW
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
1 #ifndef SkAtomics_std_DEFINED 8 #ifndef SkAtomics_std_DEFINED
2 #define SkAtomics_std_DEFINED 9 #define SkAtomics_std_DEFINED
3 10
4 // We try not to depend on the C++ standard library, 11 // We try not to depend on the C++ standard library,
5 // but these uses of <atomic> should all inline, so we don't feel to bad here. 12 // but these uses of <atomic> should all inline, so we don't feel to bad here.
6 #include <atomic> 13 #include <atomic>
7 14
8 template <typename T> 15 template <typename T>
9 T sk_atomic_load(const T* ptr, sk_memory_order mo) { 16 T sk_atomic_load(const T* ptr, sk_memory_order mo) {
10 SkASSERT(mo == sk_memory_order_relaxed || 17 SkASSERT(mo == sk_memory_order_relaxed ||
(...skipping 29 matching lines...) Expand all
40 failure == sk_memory_order_seq_cst || 47 failure == sk_memory_order_seq_cst ||
41 failure == sk_memory_order_acquire || 48 failure == sk_memory_order_acquire ||
42 failure == sk_memory_order_consume); 49 failure == sk_memory_order_consume);
43 SkASSERT(failure <= success); 50 SkASSERT(failure <= success);
44 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); 51 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
45 return std::atomic_compare_exchange_strong_explicit(ap, expected, desired, 52 return std::atomic_compare_exchange_strong_explicit(ap, expected, desired,
46 (std::memory_order)succe ss, 53 (std::memory_order)succe ss,
47 (std::memory_order)failu re); 54 (std::memory_order)failu re);
48 } 55 }
49 56
57 template <typename T>
58 T sk_atomic_exchange(T* ptr, T val, sk_memory_order mo) {
59 // All values of mo are valid.
60 std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
61 return std::atomic_exchange_explicit(ap, val, (std::memory_order)mo);
62 }
63
50 #endif//SkAtomics_std_DEFINED 64 #endif//SkAtomics_std_DEFINED
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698