| OLD | NEW |
| 1 #ifndef SkMutex_DEFINED | 1 #ifndef SkMutex_DEFINED |
| 2 #define SkMutex_DEFINED | 2 #define SkMutex_DEFINED |
| 3 | 3 |
| 4 // This file is not part of the public Skia API. | 4 // This file is not part of the public Skia API. |
| 5 #include "SkTypes.h" | 5 #include "SkTypes.h" |
| 6 | 6 |
| 7 #if defined(SK_BUILD_FOR_WIN) | 7 #if defined(SK_BUILD_FOR_WIN) |
| 8 #include "../ports/SkMutex_win.h" | 8 #include "../ports/SkMutex_win.h" |
| 9 #else | 9 #else |
| 10 #include "../ports/SkMutex_pthread.h" | 10 #include "../ports/SkMutex_pthread.h" |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 class SkAutoMutexAcquire : SkNoncopyable { |
| 14 public: |
| 15 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { |
| 16 SkASSERT(fMutex != NULL); |
| 17 mutex.acquire(); |
| 18 } |
| 19 |
| 20 explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { |
| 21 if (mutex) { |
| 22 mutex->acquire(); |
| 23 } |
| 24 } |
| 25 |
| 26 /** If the mutex has not been released, release it now. */ |
| 27 ~SkAutoMutexAcquire() { |
| 28 if (fMutex) { |
| 29 fMutex->release(); |
| 30 } |
| 31 } |
| 32 |
| 33 /** If the mutex has not been released, release it now. */ |
| 34 void release() { |
| 35 if (fMutex) { |
| 36 fMutex->release(); |
| 37 fMutex = NULL; |
| 38 } |
| 39 } |
| 40 |
| 41 /** Assert that we're holding the mutex. */ |
| 42 void assertHeld() { |
| 43 SkASSERT(fMutex); |
| 44 fMutex->assertHeld(); |
| 45 } |
| 46 |
| 47 private: |
| 48 SkBaseMutex* fMutex; |
| 49 }; |
| 50 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
| 51 |
| 52 |
| 13 #endif//SkMutex_DEFINED | 53 #endif//SkMutex_DEFINED |
| OLD | NEW |