diff options
author | 2015-07-09 13:44:32 -0700 | |
---|---|---|
committer | 2015-07-09 13:44:32 -0700 | |
commit | ac09471140ffc9f7cdf07cfa1a5fdc311b3747b5 (patch) | |
tree | e7c6258b3056472a4e7026f731b88088d32d5418 /include/core/SkMutex.h | |
parent | 7b670db2b4eb0265e69038add7ae79441d77bbc5 (diff) |
Create a template AutoTAcquire, and specialize an SkMutex version.
Add copyright notice.
BUG=skia:
Review URL: https://codereview.chromium.org/1230583008
Diffstat (limited to 'include/core/SkMutex.h')
-rw-r--r-- | include/core/SkMutex.h | 21 |
1 files 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 <typename Lock> +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<SkBaseMutex> SkAutoMutexAcquire; + #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |