diff options
author | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-16 13:13:29 +0000 |
---|---|---|
committer | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2012-07-16 13:13:29 +0000 |
commit | e3f84f3911d6ab1c99030fef3200199755251d51 (patch) | |
tree | 6b49e6c64b5ee84be0e3c032062eb14f7fb0fa90 /include/core | |
parent | fde2c0af2fd5aae19ab6c8b5228debd5b6209856 (diff) |
Add a skia method to perform an atomic add.
Complements sk_atomic_inc for when you want to increase by more than one.
Review URL: https://codereview.appspot.com/6350106
git-svn-id: http://skia.googlecode.com/svn/trunk@4614 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core')
-rw-r--r-- | include/core/SkThread.h | 1 | ||||
-rw-r--r-- | include/core/SkThread_platform.h | 17 |
2 files changed, 16 insertions, 2 deletions
diff --git a/include/core/SkThread.h b/include/core/SkThread.h index 2fd5052b06..5b1fc1c213 100644 --- a/include/core/SkThread.h +++ b/include/core/SkThread.h @@ -16,6 +16,7 @@ /****** SkThread_platform needs to define the following... int32_t sk_atomic_inc(int32_t*); +int32_t sk_atomic_add(int32_t*, int32_t); int32_t sk_atomic_dec(int32_t*); int32_t sk_atomic_conditional_inc(int32_t*); diff --git a/include/core/SkThread_platform.h b/include/core/SkThread_platform.h index cb05c50f3a..19fcd4a743 100644 --- a/include/core/SkThread_platform.h +++ b/include/core/SkThread_platform.h @@ -23,6 +23,10 @@ static inline __attribute__((always_inline)) int32_t sk_atomic_inc(int32_t *addr return __sync_fetch_and_add(addr, 1); } +static inline __attribute__((always_inline)) int32_t sk_atomic_add(int32_t *addr, int32_t value) { + return __sync_fetch_and_add(addr, value); +} + static inline __attribute__((always_inline)) int32_t sk_atomic_dec(int32_t *addr) { return __sync_fetch_and_add(addr, -1); } @@ -54,8 +58,9 @@ static inline __attribute__((always_inline)) void sk_membar_aquire__after_atomic */ #include <utils/Atomic.h> -#define sk_atomic_inc(addr) android_atomic_inc(addr) -#define sk_atomic_dec(addr) android_atomic_dec(addr) +#define sk_atomic_inc(addr) android_atomic_inc(addr) +#define sk_atomic_add(addr, value) android_atomic_add(value, addr) +#define sk_atomic_dec(addr) android_atomic_dec(addr) void sk_membar_aquire__after_atomic_dec() { //HACK: Android is actually using full memory barriers. // Should this change, uncomment below. @@ -92,6 +97,14 @@ void sk_membar_aquire__after_atomic_conditional_inc() { */ SK_API int32_t sk_atomic_inc(int32_t* addr); +/** Implemented by the porting layer, this function adds value to the int + specified by the address (in a thread-safe manner), and returns the + previous value. + No additional memory barrier is required. + This must act as a compiler barrier. + */ +SK_API int32_t sk_atomic_add(int32_t* addr, int32_t value); + /** Implemented by the porting layer, this function subtracts one from the int specified by the address (in a thread-safe manner), and returns the previous value. |