From ac09471140ffc9f7cdf07cfa1a5fdc311b3747b5 Mon Sep 17 00:00:00 2001 From: herb Date: Thu, 9 Jul 2015 13:44:32 -0700 Subject: [PATCH] Create a template AutoTAcquire, and specialize an SkMutex version. Add copyright notice. BUG=skia: Review URL: https://codereview.chromium.org/1230583008 --- include/core/SkMutex.h | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/include/core/SkMutex.h b/include/core/SkMutex.h index ea7e81726b..08b220c396 100644 --- a/include/core/SkMutex.h +++ b/include/core/SkMutex.h @@ -1,3 +1,10 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + #ifndef SkMutex_DEFINED #define SkMutex_DEFINED @@ -10,21 +17,22 @@ #include "../ports/SkMutex_pthread.h" #endif -class SkAutoMutexAcquire : SkNoncopyable { +template +class SkAutoTAcquire : SkNoncopyable { public: - explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { + explicit SkAutoTAcquire(Lock& mutex) : fMutex(&mutex) { SkASSERT(fMutex != NULL); mutex.acquire(); } - explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { + explicit SkAutoTAcquire(Lock* mutex) : fMutex(mutex) { if (mutex) { mutex->acquire(); } } /** If the mutex has not been released, release it now. */ - ~SkAutoMutexAcquire() { + ~SkAutoTAcquire() { if (fMutex) { fMutex->release(); } @@ -45,8 +53,11 @@ public: } private: - SkBaseMutex* fMutex; + Lock* fMutex; }; + +typedef SkAutoTAcquire SkAutoMutexAcquire; + #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)