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

Unified Diff: include/core/SkAtomics.h

Issue 955803002: SkTRacy<T> -> SkAtomic<T> (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: great warning Created 5 years, 10 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 | « no previous file | include/core/SkDynamicAnnotations.h » ('j') | src/core/SkPixelRef.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkAtomics.h
diff --git a/include/core/SkAtomics.h b/include/core/SkAtomics.h
index f7924153a8bdea39674104bc98dfb63d2aa7808e..d61b47a4fda514e8490614b6504903547de8164c 100644
--- a/include/core/SkAtomics.h
+++ b/include/core/SkAtomics.h
@@ -26,6 +26,26 @@ template <typename T>
bool sk_atomic_compare_exchange(T*, T* expected, T desired,
sk_memory_order success = sk_memory_order_seq_cst,
sk_memory_order failure = sk_memory_order_seq_cst);
+
+// A little wrapper class for small T (think, builtins: int, float, void*) to
+// ensure they're always used atomically. This is our stand-in for std::atomic<T>.
+template <typename T>
+class SkAtomic : SkNoncopyable {
+public:
+ SkAtomic() {}
+
+ // It is essential we return by value rather than by const&. fVal may change at any time.
+ T load(sk_memory_order mo = sk_memory_order_seq_cst) const {
+ return sk_atomic_load(&fVal, mo);
+ }
+
+ void store(const T& val, sk_memory_order mo = sk_memory_order_seq_cst) {
+ sk_atomic_store(&fVal, val, mo);
+ }
+private:
+ T fVal;
+};
+
#if defined(_MSC_VER)
#include "../ports/SkAtomics_std.h"
#elif !defined(SK_BUILD_FOR_IOS) && defined(__ATOMIC_RELAXED)
« no previous file with comments | « no previous file | include/core/SkDynamicAnnotations.h » ('j') | src/core/SkPixelRef.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698