| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
| 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 SkThread_DEFINED | 8 #ifndef SkThread_DEFINED |
| 9 #define SkThread_DEFINED | 9 #define SkThread_DEFINED |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 */ | 44 */ |
| 45 static void sk_membar_acquire__after_atomic_dec(); | 45 static void sk_membar_acquire__after_atomic_dec(); |
| 46 | 46 |
| 47 /** If sk_atomic_conditional_inc does not act as an acquire (L/SL) barrier, | 47 /** If sk_atomic_conditional_inc does not act as an acquire (L/SL) barrier, |
| 48 * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. | 48 * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. |
| 49 */ | 49 */ |
| 50 static void sk_membar_acquire__after_atomic_conditional_inc(); | 50 static void sk_membar_acquire__after_atomic_conditional_inc(); |
| 51 | 51 |
| 52 #include SK_ATOMICS_PLATFORM_H | 52 #include SK_ATOMICS_PLATFORM_H |
| 53 | 53 |
| 54 // This is POD and must be zero-initialized. | |
| 55 struct SkSpinlock { | |
| 56 void acquire() { | |
| 57 SkASSERT(shouldBeZero == 0); | |
| 58 // No memory barrier needed, but sk_atomic_cas gives us at least release
anyway. | |
| 59 while (!sk_atomic_cas(&thisIsPrivate, 0, 1)) { | |
| 60 // spin | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void release() { | |
| 65 SkASSERT(shouldBeZero == 0); | |
| 66 // This requires a release memory barrier before storing, which sk_atomi
c_cas guarantees. | |
| 67 SkAssertResult(sk_atomic_cas(&thisIsPrivate, 1, 0)); | |
| 68 } | |
| 69 | |
| 70 int32_t thisIsPrivate; | |
| 71 SkDEBUGCODE(int32_t shouldBeZero;) | |
| 72 }; | |
| 73 | |
| 74 class SkAutoSpinlock : SkNoncopyable { | |
| 75 public: | |
| 76 explicit SkAutoSpinlock(SkSpinlock* lock) : fLock(lock) { fLock->acquire();
} | |
| 77 ~SkAutoSpinlock() { fLock->release(); } | |
| 78 private: | |
| 79 SkSpinlock* fLock; | |
| 80 }; | |
| 81 #define SkAutoSpinlock(...) SK_REQUIRE_LOCAL_VAR(SkAutoSpinlock) | |
| 82 | |
| 83 /** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. | 54 /** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. |
| 84 | 55 |
| 85 class SkBaseMutex { | 56 class SkBaseMutex { |
| 86 public: | 57 public: |
| 87 void acquire(); | 58 void acquire(); |
| 88 void release(); | 59 void release(); |
| 89 }; | 60 }; |
| 90 | 61 |
| 91 class SkMutex : SkBaseMutex { | 62 class SkMutex : SkBaseMutex { |
| 92 public: | 63 public: |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 fMutex = NULL; | 99 fMutex = NULL; |
| 129 } | 100 } |
| 130 } | 101 } |
| 131 | 102 |
| 132 private: | 103 private: |
| 133 SkBaseMutex* fMutex; | 104 SkBaseMutex* fMutex; |
| 134 }; | 105 }; |
| 135 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) | 106 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
| 136 | 107 |
| 137 #endif | 108 #endif |
| OLD | NEW |