aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkMutex.h
diff options
context:
space:
mode:
authorGravatar herb <herb@google.com>2015-07-09 13:44:32 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-09 13:44:32 -0700
commitac09471140ffc9f7cdf07cfa1a5fdc311b3747b5 (patch)
treee7c6258b3056472a4e7026f731b88088d32d5418 /include/core/SkMutex.h
parent7b670db2b4eb0265e69038add7ae79441d77bbc5 (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.h21
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)