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

Unified Diff: src/core/SkLazyFnPtr.h

Issue 1317263007: Port SkLazyFnPtr users to SkOncePtr. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkLazyFnPtr.h
diff --git a/src/core/SkLazyFnPtr.h b/src/core/SkLazyFnPtr.h
deleted file mode 100644
index 153578201ae83bba39f6d24e7af5c57072afbc54..0000000000000000000000000000000000000000
--- a/src/core/SkLazyFnPtr.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Copyright 2014 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-#ifndef SkLazyFnPtr_DEFINED
-#define SkLazyFnPtr_DEFINED
-
-/** Declare a lazily-chosen static function pointer of type F.
- *
- * Example usage:
- *
- * typedef int (*FooImpl)(int, int);
- *
- * static FooImpl choose_foo() { return ... };
- *
- * int Foo(int a, int b) {
- * SK_DECLARE_STATIC_LAZY_FN_PTR(FooImpl, foo, choose_foo);
- * return foo.get()(a, b);
- * }
- *
- * You can think of SK_DECLARE_STATIC_LAZY_FN_PTR as a cheaper specialization of SkOnce.
- * There is no mutex, and in the fast path, no memory barriers are issued.
- *
- * This must be used in a global or function scope, not as a class member.
- */
-#define SK_DECLARE_STATIC_LAZY_FN_PTR(F, name, Choose) static Private::SkLazyFnPtr<F, Choose> name
-
-
-// Everything below here is private implementation details. Don't touch, don't even look.
-
-#include "SkAtomics.h"
-
-namespace Private {
-
-// This has no constructor and must be zero-initialized (the macro above does this).
-template <typename F, F (*Choose)()>
-class SkLazyFnPtr {
-public:
- F get() {
- // First, try reading to see if it's already set.
- F fn = (F)sk_atomic_load(&fPtr, sk_memory_order_relaxed);
- if (fn != nullptr) {
- return fn;
- }
-
- // We think it's not already set.
- fn = Choose();
-
- // No particular memory barriers needed; we're not guarding anything but the pointer itself.
- F prev = (F)sk_atomic_cas(&fPtr, nullptr, (void*)fn);
-
- // If prev != nullptr, someone snuck in and set fPtr concurrently.
- // If prev == nullptr, we did write fn to fPtr.
- return prev != nullptr ? prev : fn;
- }
-
-private:
- void* fPtr;
-};
-
-} // namespace Private
-
-#endif//SkLazyFnPtr_DEFINED
« no previous file with comments | « no previous file | src/ports/SkFontHost_mac.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698