aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-09-08 08:19:33 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-09-08 08:19:34 -0700
commitbbd40183ae5f5dd3ae6e8ad3cf89cf5c27ce754b (patch)
treeab69f0d687d4496e862f033714643b84ac779036 /src/core
parenta5f46e18212e8f4812ae25fda3acc6a5217613b1 (diff)
Port SkLazyFnPtr users to SkOncePtr.
First baby step on road to replacing SkLazyFnPtr, SkLazyPtr, and SkOnce. One of those very unusual times you get to use a function type, not a function pointer type! BUG=skia: Review URL: https://codereview.chromium.org/1317263007
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkLazyFnPtr.h66
1 files changed, 0 insertions, 66 deletions
diff --git a/src/core/SkLazyFnPtr.h b/src/core/SkLazyFnPtr.h
deleted file mode 100644
index 153578201a..0000000000
--- 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