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

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

Issue 1555953004: Create debug only SkSingleOwner (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: tweaks 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
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * Copyright 2016 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8 #ifndef GrSingleOwner_DEFINED
9 #define GrSingleOwner_DEFINED
10
11 #include "SkTypes.h"
12
13 #ifdef SK_DEBUG
14 #include "SkMutex.h"
15 #include "SkThreadID.h"
16
17 // This is a debug tool to verify an object is only being used from one thread a t a time.
18 class GrSingleOwner {
19 public:
20 GrSingleOwner() : fOwner(kIllegalThreadID), fReentranceCount(0) {}
21
22 struct AutoEnforce {
23 AutoEnforce(GrSingleOwner* so) : fSO(so) { fSO->enter(); }
24 ~AutoEnforce() { fSO->exit(); }
25
26 GrSingleOwner* fSO;
27 };
28
29 private:
30 void enter() {
31 SkAutoMutexAcquire lock(fMutex);
32 SkThreadID self = SkGetThreadID();
33 SkASSERT(fOwner == self || fOwner == kIllegalThreadID);
34 fReentranceCount++;
35 fOwner = self;
36 }
37
38 void exit() {
39 SkAutoMutexAcquire lock(fMutex);
40 fReentranceCount--;
41 if (fReentranceCount == 0) {
42 fOwner = kIllegalThreadID;
43 }
44 }
45
46 SkMutex fMutex;
47 SkThreadID fOwner; // guarded by fMutex
48 int fReentranceCount; // guarded by fMutex
49 };
50 #endif
51
52 #endif
OLDNEW
« no previous file with comments | « include/gpu/GrDrawContext.h ('k') | src/gpu/GrContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698