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

Side by Side Diff: include/private/SkOnce.h

Issue 1734383002: Modernize SkSpinlock. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: std::atomic<bool> Created 4 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 | « dm/DM.cpp ('k') | include/private/SkSpinlock.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 2013 Google Inc. 2 * Copyright 2013 Google Inc.
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 SkOnce_DEFINED 8 #ifndef SkOnce_DEFINED
9 #define SkOnce_DEFINED 9 #define SkOnce_DEFINED
10 10
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 // This class has no constructor and must be zero-initialized (the macro above d oes this). 52 // This class has no constructor and must be zero-initialized (the macro above d oes this).
53 class SkOnceFlag { 53 class SkOnceFlag {
54 public: 54 public:
55 bool* mutableDone() { return &fDone; } 55 bool* mutableDone() { return &fDone; }
56 56
57 void acquire() { fSpinlock.acquire(); } 57 void acquire() { fSpinlock.acquire(); }
58 void release() { fSpinlock.release(); } 58 void release() { fSpinlock.release(); }
59 59
60 private: 60 private:
61 bool fDone; 61 bool fDone;
62 SkPODSpinlock fSpinlock; 62 SkSpinlock fSpinlock;
63 }; 63 };
64 64
65 // We've pulled a pretty standard double-checked locking implementation apart 65 // We've pulled a pretty standard double-checked locking implementation apart
66 // into its main fast path and a slow path that's called when we suspect the 66 // into its main fast path and a slow path that's called when we suspect the
67 // one-time code hasn't run yet. 67 // one-time code hasn't run yet.
68 68
69 // This is the guts of the code, called when we suspect the one-time code hasn't been run yet. 69 // This is the guts of the code, called when we suspect the one-time code hasn't been run yet.
70 // This should be rarely called, so we separate it from SkOnce and don't mark it as inline. 70 // This should be rarely called, so we separate it from SkOnce and don't mark it as inline.
71 // (We don't mind if this is an actual function call, but odds are it'll be inli ned anyway.) 71 // (We don't mind if this is an actual function call, but odds are it'll be inli ned anyway.)
72 template <typename Lock, typename Arg> 72 template <typename Lock, typename Arg>
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 inline void SkOnce(SkOnceFlag* once, void (*func)()) { 130 inline void SkOnce(SkOnceFlag* once, void (*func)()) {
131 return SkOnce(once, sk_once_no_arg_adaptor, func); 131 return SkOnce(once, sk_once_no_arg_adaptor, func);
132 } 132 }
133 133
134 template <typename Lock> 134 template <typename Lock>
135 inline void SkOnce(bool* done, Lock* lock, void (*func)()) { 135 inline void SkOnce(bool* done, Lock* lock, void (*func)()) {
136 return SkOnce(done, lock, sk_once_no_arg_adaptor, func); 136 return SkOnce(done, lock, sk_once_no_arg_adaptor, func);
137 } 137 }
138 138
139 #endif // SkOnce_DEFINED 139 #endif // SkOnce_DEFINED
OLDNEW
« no previous file with comments | « dm/DM.cpp ('k') | include/private/SkSpinlock.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698