Index: include/core/SkThread.h |
diff --git a/include/core/SkThread.h b/include/core/SkThread.h |
index 7e2c90ed519295d2f3d0a526c684a6034d3e5669..2c42c158751a9314b94ee746aa79830926d010e8 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 int32_t sk_atomic_conditional_inc(int32_t* addr) { |
+ int32_t prev; |
+ do { |
+ prev = *addr; |
bungeman-skia
2014/05/27 14:20:20
Eck, it irks me that we have to do this load on al
mtklein
2014/05/27 14:27:27
Agreed. sk_atomic_cas is a bit least-common-denom
|
+ if (0 == prev) { |
reed1
2014/05/27 14:36:18
Why the test/break? Does this warrent a comment?
mtklein
2014/05/27 14:38:30
Would return 0 be clearer? That's the conditional
reed1
2014/05/27 14:44:19
Ah, no, my bad. I didn't read the bloody name of t
|
+ break; |
+ } |
+ } while (!sk_atomic_cas(addr, prev, prev+1)); |
+ return prev; |
+} |
+ |
/** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. |
class SkBaseMutex { |