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

Side by Side Diff: src/core/SkLazyFnPtr.h

Issue 1316233002: Style Change: NULL->nullptr (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 2015-08-27 (Thursday) 10:25:06 EDT Created 5 years, 3 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 | « src/core/SkLayerInfo.h ('k') | src/core/SkLightingShader.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 2014 Google Inc. 2 * Copyright 2014 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 SkLazyFnPtr_DEFINED 8 #ifndef SkLazyFnPtr_DEFINED
9 #define SkLazyFnPtr_DEFINED 9 #define SkLazyFnPtr_DEFINED
10 10
(...skipping 24 matching lines...) Expand all
35 35
36 namespace Private { 36 namespace Private {
37 37
38 // This has no constructor and must be zero-initialized (the macro above does th is). 38 // This has no constructor and must be zero-initialized (the macro above does th is).
39 template <typename F, F (*Choose)()> 39 template <typename F, F (*Choose)()>
40 class SkLazyFnPtr { 40 class SkLazyFnPtr {
41 public: 41 public:
42 F get() { 42 F get() {
43 // First, try reading to see if it's already set. 43 // First, try reading to see if it's already set.
44 F fn = (F)sk_atomic_load(&fPtr, sk_memory_order_relaxed); 44 F fn = (F)sk_atomic_load(&fPtr, sk_memory_order_relaxed);
45 if (fn != NULL) { 45 if (fn != nullptr) {
46 return fn; 46 return fn;
47 } 47 }
48 48
49 // We think it's not already set. 49 // We think it's not already set.
50 fn = Choose(); 50 fn = Choose();
51 51
52 // No particular memory barriers needed; we're not guarding anything but the pointer itself. 52 // No particular memory barriers needed; we're not guarding anything but the pointer itself.
53 F prev = (F)sk_atomic_cas(&fPtr, NULL, (void*)fn); 53 F prev = (F)sk_atomic_cas(&fPtr, nullptr, (void*)fn);
54 54
55 // If prev != NULL, someone snuck in and set fPtr concurrently. 55 // If prev != nullptr, someone snuck in and set fPtr concurrently.
56 // If prev == NULL, we did write fn to fPtr. 56 // If prev == nullptr, we did write fn to fPtr.
57 return prev != NULL ? prev : fn; 57 return prev != nullptr ? prev : fn;
58 } 58 }
59 59
60 private: 60 private:
61 void* fPtr; 61 void* fPtr;
62 }; 62 };
63 63
64 } // namespace Private 64 } // namespace Private
65 65
66 #endif//SkLazyFnPtr_DEFINED 66 #endif//SkLazyFnPtr_DEFINED
OLDNEW
« no previous file with comments | « src/core/SkLayerInfo.h ('k') | src/core/SkLightingShader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698