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

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: add sentinels to GrContext 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 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
47 } 47 }
48 48
49 void assertHeld() { 49 void assertHeld() {
50 SkASSERT(fOwner == SkGetThreadID()); 50 SkASSERT(fOwner == SkGetThreadID());
51 } 51 }
52 52
53 SkBaseSemaphore fSemaphore; 53 SkBaseSemaphore fSemaphore;
54 SkDEBUGCODE(SkThreadID fOwner;) 54 SkDEBUGCODE(SkThreadID fOwner;)
55 }; 55 };
56 56
57 #ifdef SK_DEBUG
58 // This is a slow recursive mutex for debug purposes only
59 struct SkRecursiveMutex {
60 SkRecursiveMutex () {
61 fSemaphore = SK_MUTEX_SEMAPHORE_INIT;
62 fOwner = kIllegalThreadID;
63 fAcquireCount = 0;
64 }
65 ~SkRecursiveMutex () { fSemaphore.deleteSemaphore(); }
66
67 void acquire() {
68 if (fOwner != SkGetThreadID()) {
69 fSemaphore.wait();
70 }
71 fAcquireCount++;
72 fOwner = SkGetThreadID();
73 }
74
75 void release() {
76 this->assertHeld();
77 if (1 == fAcquireCount--) {
78 fOwner = kIllegalThreadID;
79 fSemaphore.signal();
80 }
81 }
82
83 void assertHeld() {
84 SkASSERT(fOwner == SkGetThreadID());
85 }
86
87 void assertNotHeld() {
88 SkASSERT(kIllegalThreadID == fOwner);
89 }
90
91 SkBaseSemaphore fSemaphore;
92 SkThreadID fOwner;
93 uint32_t fAcquireCount;
94 };
95 #endif
96
57 // This needs to use subclassing instead of encapsulation to make SkAutoMutexAcq uire to work. 97 // This needs to use subclassing instead of encapsulation to make SkAutoMutexAcq uire to work.
58 class SkMutex : public SkBaseMutex { 98 class SkMutex : public SkBaseMutex {
59 public: 99 public:
60 SkMutex () { 100 SkMutex () {
61 fSemaphore = SK_MUTEX_SEMAPHORE_INIT; 101 fSemaphore = SK_MUTEX_SEMAPHORE_INIT;
62 SkDEBUGCODE(fOwner = kIllegalThreadID); 102 SkDEBUGCODE(fOwner = kIllegalThreadID);
63 } 103 }
64 ~SkMutex () { fSemaphore.deleteSemaphore(); } 104 ~SkMutex () { fSemaphore.deleteSemaphore(); }
65 SkMutex(const SkMutex&) = delete; 105 SkMutex(const SkMutex&) = delete;
66 SkMutex& operator=(const SkMutex&) = delete; 106 SkMutex& operator=(const SkMutex&) = delete;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 Lock &fLock; 156 Lock &fLock;
117 }; 157 };
118 158
119 typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire; 159 typedef SkAutoTAcquire<SkBaseMutex> SkAutoMutexAcquire;
120 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) 160 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
121 161
122 typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive; 162 typedef SkAutoTExclusive<SkBaseMutex> SkAutoMutexExclusive;
123 #define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive) 163 #define SkAutoMutexExclusive(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexExclusive)
124 164
125 #endif//SkMutex_DEFINED 165 #endif//SkMutex_DEFINED
OLDNEW
« no previous file with comments | « include/gpu/GrContext.h ('k') | src/gpu/GrContext.cpp » ('j') | src/gpu/GrContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698