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

Unified Diff: include/core/SkThread.h

Issue 300553003: Implement sk_atomic_conditional_inc with sk_atomic_cas. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: inline Created 6 years, 7 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 | src/ports/SkAtomics_android.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkThread.h
diff --git a/include/core/SkThread.h b/include/core/SkThread.h
index 7e2c90ed519295d2f3d0a526c684a6034d3e5669..c8cd4e9112aad6492ece41d40c06ac8d628a8b37 100644
--- a/include/core/SkThread.h
+++ b/include/core/SkThread.h
@@ -27,12 +27,6 @@ static int32_t sk_atomic_add(int32_t* addr, int32_t inc);
*/
static int32_t sk_atomic_dec(int32_t* addr);
-/** Atomically adds one to the int referenced by addr iff the referenced int was not 0
- * and returns the previous value.
- * No additional memory barrier is required; this must act as a compiler barrier.
- */
-static int32_t sk_atomic_conditional_inc(int32_t* addr);
-
/** Atomic compare and set.
* If *addr == before, set *addr to after and return true, otherwise return false.
* This must act as a release (SL/S) memory barrier and as a compiler barrier.
@@ -51,6 +45,21 @@ static void sk_membar_acquire__after_atomic_conditional_inc();
#include SK_ATOMICS_PLATFORM_H
+/** Atomically adds one to the int referenced by addr iff the referenced int was not 0
+ * and returns the previous value.
+ * No additional memory barrier is required; this must act as a compiler barrier.
+ */
+static inline int32_t sk_atomic_conditional_inc(int32_t* addr) {
+ int32_t prev;
+ do {
+ prev = *addr;
+ if (0 == prev) {
+ break;
+ }
+ } while (!sk_atomic_cas(addr, prev, prev+1));
+ return prev;
+}
+
/** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations.
class SkBaseMutex {
« no previous file with comments | « no previous file | src/ports/SkAtomics_android.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698