Chromium Code Reviews| Index: include/core/SkThread.h |
| =================================================================== |
| --- include/core/SkThread.h (revision 10251) |
| +++ include/core/SkThread.h (working copy) |
| @@ -1,4 +1,3 @@ |
| - |
| /* |
| * Copyright 2006 The Android Open Source Project |
| * |
| @@ -6,31 +5,68 @@ |
| * found in the LICENSE file. |
| */ |
| - |
| #ifndef SkThread_DEFINED |
| #define SkThread_DEFINED |
| #include "SkTypes.h" |
| -#include "SkThread_platform.h" |
| -/****** SkThread_platform needs to define the following... |
| +// SK_ATOMICS_PLATFORM_H must provide inline implementations for the following declarations. |
| -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*); |
| +/** Atomically adds one to the int referenced by addr and returns the previous value. |
| + * No additional memory barrier is required; this must act as a compiler barrier. |
| + */ |
| +static int32_t sk_atomic_inc(int32_t* addr); |
| -class SkMutex { |
| +/** Atomically adds inc to the int referenced by addrand returns the previous value. |
|
djsollen
2013/07/25 16:00:34
missing space in 'addrand'
bungeman-skia
2013/09/26 17:16:23
Done.
|
| + * No additional memory barrier is required; this must act as a compiler barrier. |
| + */ |
| +static int32_t sk_atomic_add(int32_t* addr, int32_t inc); |
| + |
| +/** Atomically subtracts one from the int referenced by addr and returns the previous value. |
| + * This must act as a release (SL/S) memory barrier and as a compiler barrier. |
| + */ |
| +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); |
| + |
| +/** If sk_atomic_dec does not act as an acquire (L/SL) barrier, |
| + * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. |
| + */ |
| +static void sk_membar_acquire__after_atomic_dec(); |
|
djsollen
2013/07/25 16:00:34
do we need these two membar_aquire* functions as i
bungeman-skia
2013/09/26 17:16:23
Correctness and documentation. Many (all?) lock-fr
|
| + |
| +/** If sk_atomic_conditional_inc does not act as an acquire (L/SL) barrier, |
| + * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. |
| + */ |
| +static void sk_membar_acquire__after_atomic_conditional_inc(); |
| + |
| +#include SK_ATOMICS_PLATFORM_H |
| + |
| + |
| +/** SK_MUTEX_PLATFORM_H must provide the following (or equivelent) declarations. |
|
djsollen
2013/07/25 16:00:34
equivalent
bungeman-skia
2013/09/26 17:16:23
Done.
|
| + |
| +class SkBaseMutex { |
| public: |
| + void acquire(); |
| + void release(); |
| +}; |
| + |
| +class SkMutex : SkBaseMutex { |
| +public: |
| SkMutex(); |
| ~SkMutex(); |
| - |
| - void acquire(); |
| - void release(); |
| }; |
| -****************/ |
| +#define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = ... |
| +#define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = ... |
| +*/ |
| +#include SK_MUTEX_PLATFORM_H |
| + |
| + |
| class SkAutoMutexAcquire : SkNoncopyable { |
| public: |
| explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { |
| @@ -38,22 +74,20 @@ |
| mutex.acquire(); |
| } |
| - SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { |
| + explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { |
| if (mutex) { |
| mutex->acquire(); |
| } |
| } |
| - /** If the mutex has not been release, release it now. |
| - */ |
| + /** If the mutex has not been released, release it now. */ |
| ~SkAutoMutexAcquire() { |
| if (fMutex) { |
| fMutex->release(); |
| } |
| } |
| - /** If the mutex has not been release, release it now. |
| - */ |
| + /** If the mutex has not been released, release it now. */ |
| void release() { |
| if (fMutex) { |
| fMutex->release(); |