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 26 matching lines...) Expand all Loading... |
37 /** If sk_atomic_dec does not act as an acquire (L/SL) barrier, | 37 /** If sk_atomic_dec does not act as an acquire (L/SL) barrier, |
38 * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. | 38 * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. |
39 */ | 39 */ |
40 static void sk_membar_acquire__after_atomic_dec(); | 40 static void sk_membar_acquire__after_atomic_dec(); |
41 | 41 |
42 /** If sk_atomic_conditional_inc does not act as an acquire (L/SL) barrier, | 42 /** If sk_atomic_conditional_inc does not act as an acquire (L/SL) barrier, |
43 * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. | 43 * this must act as an acquire (L/SL) memory barrier and as a compiler barrier. |
44 */ | 44 */ |
45 static void sk_membar_acquire__after_atomic_conditional_inc(); | 45 static void sk_membar_acquire__after_atomic_conditional_inc(); |
46 | 46 |
47 #include SK_ATOMICS_PLATFORM_H | 47 #ifdef GOOGLE3 |
| 48 #include "SkAtomics_sync.h" |
| 49 #else |
| 50 #include SK_ATOMICS_PLATFORM_H |
| 51 #endif |
48 | 52 |
49 /** Atomically adds one to the int referenced by addr iff the referenced int was
not 0 | 53 /** Atomically adds one to the int referenced by addr iff the referenced int was
not 0 |
50 * and returns the previous value. | 54 * and returns the previous value. |
51 * No additional memory barrier is required; this must act as a compiler barrie
r. | 55 * No additional memory barrier is required; this must act as a compiler barrie
r. |
52 */ | 56 */ |
53 template<typename INT_TYPE> static inline INT_TYPE sk_atomic_conditional_inc(INT
_TYPE* addr) { | 57 template<typename INT_TYPE> static inline INT_TYPE sk_atomic_conditional_inc(INT
_TYPE* addr) { |
54 INT_TYPE prev; | 58 INT_TYPE prev; |
55 do { | 59 do { |
56 prev = *addr; | 60 prev = *addr; |
57 if (0 == prev) { | 61 if (0 == prev) { |
(...skipping 13 matching lines...) Expand all Loading... |
71 * Only needs to be implemented for T which can be atomically read. | 75 * Only needs to be implemented for T which can be atomically read. |
72 */ | 76 */ |
73 template <typename T> T sk_acquire_load(T*); | 77 template <typename T> T sk_acquire_load(T*); |
74 | 78 |
75 /** Write T*, with at least a release barrier. | 79 /** Write T*, with at least a release barrier. |
76 * | 80 * |
77 * Only needs to be implemented for T which can be atomically written. | 81 * Only needs to be implemented for T which can be atomically written. |
78 */ | 82 */ |
79 template <typename T> void sk_release_store(T*, T); | 83 template <typename T> void sk_release_store(T*, T); |
80 | 84 |
81 #include SK_BARRIERS_PLATFORM_H | 85 #ifdef GOOGLE3 |
| 86 #include "SkBarriers_x86.h" |
| 87 #else |
| 88 #include SK_BARRIERS_PLATFORM_H |
| 89 #endif |
82 | 90 |
83 /** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. | 91 /** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. |
84 | 92 |
85 class SkBaseMutex { | 93 class SkBaseMutex { |
86 public: | 94 public: |
87 void acquire(); // Block until this thread owns the mutex. | 95 void acquire(); // Block until this thread owns the mutex. |
88 void release(); // Assuming this thread owns the mutex, release it. | 96 void release(); // Assuming this thread owns the mutex, release it. |
89 void assertHeld(); // If SK_DEBUG, assert this thread owns the mutex. | 97 void assertHeld(); // If SK_DEBUG, assert this thread owns the mutex. |
90 }; | 98 }; |
91 | 99 |
92 class SkMutex : SkBaseMutex { | 100 class SkMutex : SkBaseMutex { |
93 public: | 101 public: |
94 SkMutex(); | 102 SkMutex(); |
95 ~SkMutex(); | 103 ~SkMutex(); |
96 }; | 104 }; |
97 | 105 |
98 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = ... | 106 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = ... |
99 */ | 107 */ |
100 | 108 |
101 #include SK_MUTEX_PLATFORM_H | 109 #ifdef GOOGLE3 |
| 110 #include "SkMutex_pthread.h" |
| 111 #else |
| 112 #include SK_MUTEX_PLATFORM_H |
| 113 #endif |
102 | 114 |
103 | 115 |
104 class SkAutoMutexAcquire : SkNoncopyable { | 116 class SkAutoMutexAcquire : SkNoncopyable { |
105 public: | 117 public: |
106 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { | 118 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { |
107 SkASSERT(fMutex != NULL); | 119 SkASSERT(fMutex != NULL); |
108 mutex.acquire(); | 120 mutex.acquire(); |
109 } | 121 } |
110 | 122 |
111 explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { | 123 explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { |
(...skipping 22 matching lines...) Expand all Loading... |
134 SkASSERT(fMutex); | 146 SkASSERT(fMutex); |
135 fMutex->assertHeld(); | 147 fMutex->assertHeld(); |
136 } | 148 } |
137 | 149 |
138 private: | 150 private: |
139 SkBaseMutex* fMutex; | 151 SkBaseMutex* fMutex; |
140 }; | 152 }; |
141 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) | 153 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) |
142 | 154 |
143 #endif | 155 #endif |
OLD | NEW |