| * Copyright 2016 Google Inc. |
| * Use of this source code is governed by a BSD-style license that can be |
| * found in the LICENSE file. |
| #ifndef GrSingleOwner_DEFINED |
| #define GrSingleOwner_DEFINED |
| // This is a debug tool to verify an object is only being used from one thread at a time. |
| GrSingleOwner() : fOwner(kIllegalThreadID), fReentranceCount(0) {} |
| AutoEnforce(GrSingleOwner* so) : fSO(so) { fSO->enter(); } |
| ~AutoEnforce() { fSO->exit(); } |
| SkAutoMutexAcquire lock(fMutex); |
| SkThreadID self = SkGetThreadID(); |
| SkASSERT(fOwner == self || fOwner == kIllegalThreadID); |
| SkAutoMutexAcquire lock(fMutex); |
| SkASSERT(fOwner == SkGetThreadID()); |
| if (fReentranceCount == 0) { |
| fOwner = kIllegalThreadID; |
| SkThreadID fOwner; // guarded by fMutex |
| int fReentranceCount; // guarded by fMutex |
| class GrSingleOwner {}; // Provide a dummy implementation so we can pass pointers to constructors |