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

Unified Diff: include/ports/SkAtomics_std.h

Issue 896553002: Atomics overhaul. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: warning Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/ports/SkAtomics_atomic.h ('k') | include/ports/SkAtomics_sync.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/ports/SkAtomics_std.h
diff --git a/include/ports/SkAtomics_std.h b/include/ports/SkAtomics_std.h
new file mode 100644
index 0000000000000000000000000000000000000000..f1fb0e2053083cca8953f442ecc50ed469f52374
--- /dev/null
+++ b/include/ports/SkAtomics_std.h
@@ -0,0 +1,36 @@
+#ifndef SkAtomics_std_DEFINED
+#define SkAtomics_std_DEFINED
+
+// We try not to depend on the C++ standard library,
+// but these uses of <atomic> should all inline, so we don't feel to bad here.
+#include <atomic>
+
+template <typename T>
+T sk_atomic_load(const T* ptr, sk_memory_order mo) {
+ const std::atomic<T>* ap = reinterpret_cast<const std::atomic<T>*>(ptr);
+ return std::atomic_load_explicit(ap, (std::memory_order)mo);
+}
+
+template <typename T>
+void sk_atomic_store(T* ptr, T val, sk_memory_order mo) {
+ std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
+ return std::atomic_store_explicit(ap, val, (std::memory_order)mo);
+}
+
+template <typename T>
+T sk_atomic_fetch_add(T* ptr, T val, sk_memory_order mo) {
+ std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
+ return std::atomic_fetch_add_explicit(ap, val, (std::memory_order)mo);
+}
+
+template <typename T>
+bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired,
+ sk_memory_order success,
+ sk_memory_order failure) {
+ std::atomic<T>* ap = reinterpret_cast<std::atomic<T>*>(ptr);
+ return std::atomic_compare_exchange_strong_explicit(ap, expected, desired,
+ (std::memory_order)success,
+ (std::memory_order)failure);
+}
+
+#endif//SkAtomics_std_DEFINED
« 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