Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | |
| 2 * Copyright 2015 Google Inc. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license that can be | |
| 5 * found in the LICENSE file. | |
| 6 */ | |
| 7 | |
| 1 #ifndef SkMutex_DEFINED | 8 #ifndef SkMutex_DEFINED |
| 2 #define SkMutex_DEFINED | 9 #define SkMutex_DEFINED |
| 3 | 10 |
| 4 // This file is not part of the public Skia API. | 11 // This file is not part of the public Skia API. |
| 5 #include "SkTypes.h" | 12 #include "SkTypes.h" |
| 6 | 13 |
| 7 #if defined(SK_BUILD_FOR_WIN) | 14 #if defined(SK_BUILD_FOR_WIN) |
| 8 #include "../ports/SkMutex_win.h" | 15 #include "../ports/SkMutex_win.h" |
| 9 #else | 16 #else |
| 10 #include "../ports/SkMutex_pthread.h" | 17 #include "../ports/SkMutex_pthread.h" |
| 11 #endif | 18 #endif |
| 12 | 19 |
| 13 class SkAutoMutexAcquire : SkNoncopyable { | 20 template <typename Lock> |
| 21 class SkScopedLock : SkNoncopyable { | |
|
mtklein
2015/07/08 19:33:47
Why not just use SkAutoLockAcquire<Lock> ?
reed1
2015/07/08 19:36:01
For now, I suggest we keep the current skia name c
herb_g
2015/07/08 20:21:57
I agree. Regressed back to google3 naming.
herb_g
2015/07/08 20:21:57
I don't want to take the hit of checking for NULL
| |
| 14 public: | 22 public: |
| 15 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { | 23 explicit SkScopedLock(Lock& lock) : fLock(lock) { fLock.acquire(); } |
| 24 ~SkScopedLock() { fLock.release(); } | |
| 25 | |
| 26 private: | |
| 27 Lock& fLock; | |
| 28 }; | |
| 29 | |
| 30 template <typename Lock> | |
| 31 class SkAutoLockAcquire : SkNoncopyable { | |
|
reed1
2015/07/08 19:36:01
Do these two just differ by * -vs- & ? If so, that
mtklein
2015/07/08 19:36:34
yep
herb_g
2015/07/08 20:21:57
These two differ by checking for NULL all the time
| |
| 32 public: | |
| 33 explicit SkAutoLockAcquire(Lock& mutex) : fMutex(&mutex) { | |
| 16 SkASSERT(fMutex != NULL); | 34 SkASSERT(fMutex != NULL); |
| 17 mutex.acquire(); | 35 mutex.acquire(); |
| 18 } | 36 } |
| 19 | 37 |
| 20 explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { | 38 explicit SkAutoLockAcquire(Lock* mutex) : fMutex(mutex) { |
| 21 if (mutex) { | 39 if (mutex) { |
| 22 mutex->acquire(); | 40 mutex->acquire(); |
| 23 } | 41 } |
| 24 } | 42 } |
| 25 | 43 |
| 26 /** If the mutex has not been released, release it now. */ | 44 /** If the mutex has not been released, release it now. */ |
| 27 ~SkAutoMutexAcquire() { | 45 ~SkAutoLockAcquire() { |
| 28 if (fMutex) { | 46 if (fMutex) { |
| 29 fMutex->release(); | 47 fMutex->release(); |
| 30 } | 48 } |
| 31 } | 49 } |
| 32 | 50 |
| 33 /** If the mutex has not been released, release it now. */ | 51 /** If the mutex has not been released, release it now. */ |
| 34 void release() { | 52 void release() { |
| 35 if (fMutex) { | 53 if (fMutex) { |
| 36 fMutex->release(); | 54 fMutex->release(); |
| 37 fMutex = NULL; | 55 fMutex = NULL; |
| 38 } | 56 } |
| 39 } | 57 } |
| 40 | 58 |
| 41 /** Assert that we're holding the mutex. */ | 59 /** Assert that we're holding the mutex. */ |
| 42 void assertHeld() { | 60 void assertHeld() { |
| 43 SkASSERT(fMutex); | 61 SkASSERT(fMutex); |
| 44 fMutex->assertHeld(); | 62 fMutex->assertHeld(); |
| 45 } | 63 } |
| 46 | 64 |
| 47 private: | 65 private: |
| 48 SkBaseMutex* fMutex; | 66 Lock* fMutex; |
| 49 }; | 67 }; |
| 68 | |
| 69 using SkAutoMutexAcquire = SkAutoLockAcquire<SkBaseMutex>; | |
| 70 | |
| 50 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) | 71 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
| 51 | 72 |
| 52 | 73 |
| 53 #endif//SkMutex_DEFINED | 74 #endif//SkMutex_DEFINED |
| OLD | NEW |