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

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

Issue 155963003: SkOnce in is_lcd_supported instead of hand rolled double-checked locking. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: SK -> Sk Created 6 years, 10 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/SkOnce.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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
OLDNEW
« no previous file with comments | « include/core/SkOnce.h ('k') | src/ports/SkFontHost_FreeType.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698