| Index: include/core/SkMutex.h
|
| diff --git a/include/core/SkMutex.h b/include/core/SkMutex.h
|
| index 7dbe957d8b12b70758875ec3bb8997051f335684..ea7e81726b88c05828f35753c877b129eab2a15d 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
|
|
|