Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(767)

Side by Side Diff: include/core/SkThread.h

Issue 862983002: Move sync code to include/, switch from using platform define to a proxy header in core/ (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gyp Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/core/SkPostConfig.h ('k') | include/core/SkThreadPriv.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "SkTypes.h" 11 #include "SkTypes.h"
12 12
13 // SK_ATOMICS_PLATFORM_H must provide inline implementations for the following d eclarations. 13 // SkAtomics.h must provide inline implementations for the following declaration s.
14 14
15 /** Atomically adds one to the int referenced by addr and returns the previous v alue. 15 /** Atomically adds one to the int referenced by addr and returns the previous v alue.
16 * No additional memory barrier is required; this must act as a compiler barrie r. 16 * No additional memory barrier is required; this must act as a compiler barrie r.
17 */ 17 */
18 static int32_t sk_atomic_inc(int32_t* addr); 18 static int32_t sk_atomic_inc(int32_t* addr);
19 static int64_t sk_atomic_inc(int64_t* addr); 19 static int64_t sk_atomic_inc(int64_t* addr);
20 20
21 /** Atomically adds inc to the int referenced by addr and returns the previous v alue. 21 /** Atomically adds inc to the int referenced by addr and returns the previous v alue.
22 * No additional memory barrier is required; this must act as a compiler barrie r. 22 * No additional memory barrier is required; this must act as a compiler barrie r.
23 */ 23 */
(...skipping 13 matching lines...) Expand all
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 #ifdef GOOGLE3 47 #include "SkAtomics.h"
48 #include "SkAtomics_sync.h"
49 #else
50 #include SK_ATOMICS_PLATFORM_H
51 #endif
52 48
53 /** Atomically adds one to the int referenced by addr iff the referenced int was not 0 49 /** Atomically adds one to the int referenced by addr iff the referenced int was not 0
54 * and returns the previous value. 50 * and returns the previous value.
55 * No additional memory barrier is required; this must act as a compiler barrie r. 51 * No additional memory barrier is required; this must act as a compiler barrie r.
56 */ 52 */
57 template<typename INT_TYPE> static inline INT_TYPE sk_atomic_conditional_inc(INT _TYPE* addr) { 53 template<typename INT_TYPE> static inline INT_TYPE sk_atomic_conditional_inc(INT _TYPE* addr) {
58 INT_TYPE prev; 54 INT_TYPE prev;
59 do { 55 do {
60 prev = *addr; 56 prev = *addr;
61 if (0 == prev) { 57 if (0 == prev) {
62 break; 58 break;
63 } 59 }
64 } while (!sk_atomic_cas(addr, prev, prev+1)); 60 } while (!sk_atomic_cas(addr, prev, prev+1));
65 return prev; 61 return prev;
66 } 62 }
67 63
68 // SK_BARRIERS_PLATFORM_H must provide implementations for the following declara tions: 64 // SkBarriers.h must provide implementations for the following declarations:
69 65
70 /** Prevent the compiler from reordering across this barrier. */ 66 /** Prevent the compiler from reordering across this barrier. */
71 static void sk_compiler_barrier(); 67 static void sk_compiler_barrier();
72 68
73 /** Read T*, with at least an acquire barrier. 69 /** Read T*, with at least an acquire barrier.
74 * 70 *
75 * Only needs to be implemented for T which can be atomically read. 71 * Only needs to be implemented for T which can be atomically read.
76 */ 72 */
77 template <typename T> T sk_acquire_load(T*); 73 template <typename T> T sk_acquire_load(T*);
78 74
79 /** Write T*, with at least a release barrier. 75 /** Write T*, with at least a release barrier.
80 * 76 *
81 * Only needs to be implemented for T which can be atomically written. 77 * Only needs to be implemented for T which can be atomically written.
82 */ 78 */
83 template <typename T> void sk_release_store(T*, T); 79 template <typename T> void sk_release_store(T*, T);
84 80
85 #ifdef GOOGLE3 81 #include "SkBarriers.h"
86 #include "SkBarriers_x86.h"
87 #else
88 #include SK_BARRIERS_PLATFORM_H
89 #endif
90 82
91 /** SK_MUTEX_PLATFORM_H must provide the following (or equivalent) declarations. 83 /** SkMutex.h must provide the following (or equivalent) declarations.
92 84
93 class SkBaseMutex { 85 class SkBaseMutex {
94 public: 86 public:
95 void acquire(); // Block until this thread owns the mutex. 87 void acquire(); // Block until this thread owns the mutex.
96 void release(); // Assuming this thread owns the mutex, release it. 88 void release(); // Assuming this thread owns the mutex, release it.
97 void assertHeld(); // If SK_DEBUG, assert this thread owns the mutex. 89 void assertHeld(); // If SK_DEBUG, assert this thread owns the mutex.
98 }; 90 };
99 91
100 class SkMutex : SkBaseMutex { 92 class SkMutex : SkBaseMutex {
101 public: 93 public:
102 SkMutex(); 94 SkMutex();
103 ~SkMutex(); 95 ~SkMutex();
104 }; 96 };
105 97
106 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = ... 98 #define SK_DECLARE_STATIC_MUTEX(name) static SkBaseMutex name = ...
107 */ 99 */
108 100
109 #ifdef GOOGLE3 101 #include "SkMutex.h"
110 #include "SkMutex_pthread.h"
111 #else
112 #include SK_MUTEX_PLATFORM_H
113 #endif
114
115 102
116 class SkAutoMutexAcquire : SkNoncopyable { 103 class SkAutoMutexAcquire : SkNoncopyable {
117 public: 104 public:
118 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) { 105 explicit SkAutoMutexAcquire(SkBaseMutex& mutex) : fMutex(&mutex) {
119 SkASSERT(fMutex != NULL); 106 SkASSERT(fMutex != NULL);
120 mutex.acquire(); 107 mutex.acquire();
121 } 108 }
122 109
123 explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) { 110 explicit SkAutoMutexAcquire(SkBaseMutex* mutex) : fMutex(mutex) {
124 if (mutex) { 111 if (mutex) {
(...skipping 21 matching lines...) Expand all
146 SkASSERT(fMutex); 133 SkASSERT(fMutex);
147 fMutex->assertHeld(); 134 fMutex->assertHeld();
148 } 135 }
149 136
150 private: 137 private:
151 SkBaseMutex* fMutex; 138 SkBaseMutex* fMutex;
152 }; 139 };
153 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire) 140 #define SkAutoMutexAcquire(...) SK_REQUIRE_LOCAL_VAR(SkAutoMutexAcquire)
154 141
155 #endif 142 #endif
OLDNEW
« no previous file with comments | « include/core/SkPostConfig.h ('k') | include/core/SkThreadPriv.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698