| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkMutex_win_DEFINED | 8 #ifndef SkMutex_win_DEFINED |
| 9 #define SkMutex_win_DEFINED | 9 #define SkMutex_win_DEFINED |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 # undef NOMINMAX_WAS_LOCALLY_DEFINED | 29 # undef NOMINMAX_WAS_LOCALLY_DEFINED |
| 30 # undef NOMINMAX | 30 # undef NOMINMAX |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 // On Windows, SkBaseMutex and SkMutex are the same thing, | 33 // On Windows, SkBaseMutex and SkMutex are the same thing, |
| 34 // we can't easily get rid of static initializers. | 34 // we can't easily get rid of static initializers. |
| 35 class SkMutex { | 35 class SkMutex { |
| 36 public: | 36 public: |
| 37 SkMutex() { | 37 SkMutex() { |
| 38 InitializeCriticalSection(&fStorage); | 38 InitializeCriticalSection(&fStorage); |
| 39 SkDEBUGCODE(fOwner = 0;) |
| 39 } | 40 } |
| 40 | 41 |
| 41 ~SkMutex() { | 42 ~SkMutex() { |
| 43 SkASSERT(0 == fOwner); |
| 42 DeleteCriticalSection(&fStorage); | 44 DeleteCriticalSection(&fStorage); |
| 43 } | 45 } |
| 44 | 46 |
| 45 void acquire() { | 47 void acquire() { |
| 46 EnterCriticalSection(&fStorage); | 48 EnterCriticalSection(&fStorage); |
| 49 SkDEBUGCODE(fOwner = GetCurrentThreadId();) |
| 47 } | 50 } |
| 48 | 51 |
| 49 void release() { | 52 void release() { |
| 53 this->assertHeld(); |
| 54 SkDEBUGCODE(fOwner = 0;) |
| 50 LeaveCriticalSection(&fStorage); | 55 LeaveCriticalSection(&fStorage); |
| 51 } | 56 } |
| 52 | 57 |
| 58 void assertHeld() { |
| 59 SkASSERT(GetCurrentThreadId() == fOwner); |
| 60 } |
| 61 |
| 53 private: | 62 private: |
| 54 SkMutex(const SkMutex&); | 63 SkMutex(const SkMutex&); |
| 55 SkMutex& operator=(const SkMutex&); | 64 SkMutex& operator=(const SkMutex&); |
| 56 | 65 |
| 57 CRITICAL_SECTION fStorage; | 66 CRITICAL_SECTION fStorage; |
| 67 SkDEBUGCODE(DWORD fOwner;) |
| 58 }; | 68 }; |
| 59 | 69 |
| 60 typedef SkMutex SkBaseMutex; | 70 typedef SkMutex SkBaseMutex; |
| 61 | 71 |
| 62 // Windows currently provides no documented means of POD initializing a CRITICAL
_SECTION. | 72 // Windows currently provides no documented means of POD initializing a CRITICAL
_SECTION. |
| 63 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name | 73 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name |
| 64 #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name | 74 #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name |
| 65 | 75 |
| 66 #endif | 76 #endif |
| OLD | NEW |