diff options
author | 2015-02-02 12:22:07 -0800 | |
---|---|---|
committer | 2015-02-02 12:22:07 -0800 | |
commit | a669bc7a7ae7580c5cd92067aeb95d09e64ea720 (patch) | |
tree | 2ab6086a84d997e7dd01b858a5d9f6bbc43f57c9 /include/core/SkMutex.h | |
parent | 465206af184f58e8097e7f4f414b791232627c31 (diff) |
Atomics overhaul.
This merges and refactors SkAtomics.h and SkBarriers.h into SkAtomics.h and
some ports/ implementations. The major new feature is that we can express
memory orders explicitly rather than only through comments.
The porting layer is reduced to four template functions:
- sk_atomic_load
- sk_atomic_store
- sk_atomic_fetch_add
- sk_atomic_compare_exchange
From those four we can reconstruct all our previous sk_atomic_foo.
There are three ports:
- SkAtomics_std: uses C++11 <atomic>, used with MSVC
- SkAtomics_atomic: uses newer GCC/Clang intrinsics, used on not-MSVC where possible
- SkAtomics_sync: uses older GCC/Clang intrinsics, used where SkAtomics_atomic not supported
No public API changes.
TBR=reed@google.com
BUG=skia:
Review URL: https://codereview.chromium.org/896553002
Diffstat (limited to 'include/core/SkMutex.h')
-rw-r--r-- | include/core/SkMutex.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/include/core/SkMutex.h b/include/core/SkMutex.h index 7dbe957d8b..ea7e81726b 100644 --- a/include/core/SkMutex.h +++ b/include/core/SkMutex.h @@ -10,4 +10,44 @@ #include "../ports/SkMutex_pthread.h" #endif +class SkAutoMutexAcquire : SkNoncopyable { +public: + explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { + SkASSERT(fMutex != NULL); + mutex.acquire(); + } + + explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { + if (mutex) { + mutex->acquire(); + } + } + + /** If the mutex has not been released, release it now. */ + ~SkAutoMutexAcquire() { + if (fMutex) { + fMutex->release(); + } + } + + /** If the mutex has not been released, release it now. */ + void release() { + if (fMutex) { + fMutex->release(); + fMutex = NULL; + } + } + + /** Assert that we're holding the mutex. */ + void assertHeld() { + SkASSERT(fMutex); + fMutex->assertHeld(); + } + +private: + SkBaseMutex* fMutex; +}; +#define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) + + #endif//SkMutex_DEFINED |