diff options
author | 2015-03-30 08:13:33 -0700 | |
---|---|---|
committer | 2015-03-30 08:13:34 -0700 | |
commit | 50ffd9921e6dc82cae8ef143e8cecfd8bcf900fb (patch) | |
tree | 56876ee2f54e95478ad143b177abc8f34843e3dd /include/ports/SkAtomics_std.h | |
parent | ff420217394e6e35e831b11e98b46202e37de23f (diff) |
Extract the spinlock from SkOnce as SkSpinlock.
This uses slightly newer APIs from SkAtomics.h to make it a bit more efficient.
No public API changes.
TBR=reed@google.com
BUG=skia:
Review URL: https://codereview.chromium.org/1039323002
Diffstat (limited to 'include/ports/SkAtomics_std.h')
-rw-r--r-- | include/ports/SkAtomics_std.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/include/ports/SkAtomics_std.h b/include/ports/SkAtomics_std.h index e89d74981c..4c26858dfd 100644 --- a/include/ports/SkAtomics_std.h +++ b/include/ports/SkAtomics_std.h @@ -1,3 +1,10 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #ifndef SkAtomics_std_DEFINED #define SkAtomics_std_DEFINED @@ -47,4 +54,11 @@ bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, (std::memory_order)failure); } +template <typename T> +T sk_atomic_exchange(T* ptr, T val, sk_memory_order mo) { + // All values of mo are valid. + std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr); + return std::atomic_exchange_explicit(ap, val, (std::memory_order)mo); +} + #endif//SkAtomics_std_DEFINED |