OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 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_DEFINED | 8 #ifndef SkMutex_DEFINED |
9 #define SkMutex_DEFINED | 9 #define SkMutex_DEFINED |
10 | 10 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 private: | 115 private: |
116 Lock &fLock; | 116 Lock &fLock; |
117 }; | 117 }; |
118 | 118 |
119 typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire; | 119 typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire; |
120 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) | 120 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
121 | 121 |
122 typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive; | 122 typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive; |
123 #define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive) | 123 #define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive) |
124 | 124 |
| 125 #ifdef SK_DEBUG |
| 126 // This is a debug tool to verify an object is only being used from one thread a
t a time |
| 127 class SkSingleOwner { |
| 128 public: |
| 129 SkSingleOwner() : fOwner(kIllegalThreadID), fReentranceCount(0) {} |
| 130 |
| 131 struct AutoEnforce { |
| 132 AutoEnforce(SkSingleOwner* so) : fSO(so) { fSO->enter(); } |
| 133 ~AutoEnforce() { fSO->exit(); } |
| 134 |
| 135 SkSingleOwner* fSO; |
| 136 }; |
| 137 |
| 138 private: |
| 139 void enter() { |
| 140 SkAutoMutexAcquire lock(fMutex); |
| 141 SkThreadID self = SkGetThreadID(); |
| 142 SkASSERT(fOwner == self || fOwner == kIllegalThreadID); |
| 143 fReentranceCount++; |
| 144 fOwner = self; |
| 145 } |
| 146 |
| 147 void exit() { |
| 148 SkAutoMutexAcquire lock(fMutex); |
| 149 fReentranceCount--; |
| 150 if (fReentranceCount == 0) { |
| 151 fOwner = kIllegalThreadID; |
| 152 } |
| 153 } |
| 154 |
| 155 SkMutex fMutex; |
| 156 SkThreadID fOwner; // guarded by fMutex |
| 157 int fReentranceCount; // guarded by fMutex |
| 158 }; |
| 159 #endif |
| 160 |
125 #endif//SkMutex_DEFINED | 161 #endif//SkMutex_DEFINED |
OLD | NEW |