Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(312)

Side by Side Diff: include/private/SkMutex.h

Issue 1555953004: Create debug only SkSingleOwner (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: create SkSingleOwner Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
OLDNEW
« include/gpu/GrContext.h ('K') | « include/gpu/GrContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698