Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkMutex_pthread_DEFINED | 8 #ifndef SkMutex_pthread_DEFINED |
| 9 #define SkMutex_pthread_DEFINED | 9 #define SkMutex_pthread_DEFINED |
| 10 | 10 |
| 11 /** Posix pthread_mutex based mutex. */ | 11 /** Posix pthread_mutex based mutex. */ |
| 12 | 12 |
| 13 #include <errno.h> | 13 #include <errno.h> |
| 14 #include <pthread.h> | 14 #include <pthread.h> |
| 15 | 15 |
| 16 // A SkBaseMutex is a POD structure that can be directly initialized | 16 // A SkBaseMutex is a POD structure that can be directly initialized |
| 17 // at declaration time with SK_DECLARE_STATIC/GLOBAL_MUTEX. This avoids the | 17 // at declaration time with SK_DECLARE_STATIC/GLOBAL_MUTEX. This avoids the |
| 18 // generation of a static initializer in the final machine code (and | 18 // generation of a static initializer in the final machine code (and |
| 19 // a corresponding static finalizer). | 19 // a corresponding static finalizer). |
| 20 struct SkBaseMutex { | 20 struct SkBaseMutex { |
| 21 void acquire() { | 21 void acquire() { |
| 22 SkASSERT(fOwner != pthread_self()); // SkMutex is not re-entrant | |
|
mtklein
2014/06/20 15:34:31
Run this through the TSAN bot before submitting?
| |
| 22 pthread_mutex_lock(&fMutex); | 23 pthread_mutex_lock(&fMutex); |
| 23 SkDEBUGCODE(fOwner = pthread_self();) | 24 SkDEBUGCODE(fOwner = pthread_self();) |
| 24 } | 25 } |
| 25 void release() { | 26 void release() { |
| 26 this->assertHeld(); | 27 this->assertHeld(); |
| 27 SkDEBUGCODE(fOwner = 0;) | 28 SkDEBUGCODE(fOwner = 0;) |
| 28 pthread_mutex_unlock(&fMutex); | 29 pthread_mutex_unlock(&fMutex); |
| 29 } | 30 } |
| 30 void assertHeld() { | 31 void assertHeld() { |
| 31 SkASSERT(pthread_self() == fOwner); | 32 SkASSERT(pthread_self() == fOwner); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 82 | 83 |
| 83 #define SK_BASE_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, SkDEBUGCODE(0) } | 84 #define SK_BASE_MUTEX_INIT { PTHREAD_MUTEX_INITIALIZER, SkDEBUGCODE(0) } |
| 84 | 85 |
| 85 // Using POD-style initialization prevents the generation of a static initialize r. | 86 // Using POD-style initialization prevents the generation of a static initialize r. |
| 86 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = SK_BASE_MUTEX_IN IT | 87 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = SK_BASE_MUTEX_IN IT |
| 87 | 88 |
| 88 // Special case used when the static mutex must be available globally. | 89 // Special case used when the static mutex must be available globally. |
| 89 #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = SK_BASE_MUTEX_INIT | 90 #define SK_DECLARE_GLOBAL_MUTEX(name) SkBaseMutex name = SK_BASE_MUTEX_INIT |
| 90 | 91 |
| 91 #endif | 92 #endif |
| OLD | NEW |