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

Unified Diff: include/ports/SkAtomics_sync.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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/ports/SkAtomics_std.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/ports/SkAtomics_sync.h
diff --git a/include/ports/SkAtomics_sync.h b/include/ports/SkAtomics_sync.h
index 66da4d35eeb3c47524e4aeb9832aa757ee4cf8fe..7ca0b46a94a6b23f95e60d7d57109cb3325d8167 100644
--- a/include/ports/SkAtomics_sync.h
+++ b/include/ports/SkAtomics_sync.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_sync_DEFINED
#define SkAtomics_sync_DEFINED
@@ -48,4 +55,14 @@ bool sk_atomic_compare_exchange(T* ptr, T* expected, T desired, sk_memory_order,
return false;
}
+template <typename T>
+T sk_atomic_exchange(T* ptr, T val, sk_memory_order) {
+ // There is no __sync exchange. Emulate it with a CAS loop.
+ T prev;
+ do {
+ prev = sk_atomic_load(ptr);
+ } while(!sk_atomic_compare_exchange(ptr, &prev, val));
bungeman-skia 2015/03/30 14:52:17 nit: usually there is a space between the 'while'
+ return prev;
+}
+
#endif//SkAtomics_sync_DEFINED
« no previous file with comments | « include/ports/SkAtomics_std.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698