Clean up SkOnce:
1 Remove atExit feature: clients can do it just as well as SkOnce can.
2 Remove support for functors: no one but the unit test did that.
3 Remove support for unused non-static SkOnceFlag (no SK_ONCE_INIT).
4 Add SkOnce variants for no-arg functions so we're not forced to pass dummy values all the time.
5 Merge SkSpinlock and SkOnceFlag, making all members private.
6 More notes about memory barriers, adding an acquire load after acquiring the spinlock.
BUG=skia:
R=bungeman@google.com, mtklein@google.com, reed@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/302083003
diff --git a/src/utils/win/SkDWrite.cpp b/src/utils/win/SkDWrite.cpp
index 16e8ddc..87826b5 100644
--- a/src/utils/win/SkDWrite.cpp
+++ b/src/utils/win/SkDWrite.cpp
@@ -14,6 +14,12 @@
static IDWriteFactory* gDWriteFactory = NULL;
+static void release_dwrite_factory() {
+ if (gDWriteFactory) {
+ gDWriteFactory->Release();
+ }
+}
+
static void create_dwrite_factory(IDWriteFactory** factory) {
typedef decltype(DWriteCreateFactory)* DWriteCreateFactoryProc;
DWriteCreateFactoryProc dWriteCreateFactoryProc = reinterpret_cast<DWriteCreateFactoryProc>(
@@ -31,17 +37,13 @@
__uuidof(IDWriteFactory),
reinterpret_cast<IUnknown**>(factory)),
"Could not create DirectWrite factory.");
+ atexit(release_dwrite_factory);
}
-static void release_dwrite_factory() {
- if (gDWriteFactory) {
- gDWriteFactory->Release();
- }
-}
IDWriteFactory* sk_get_dwrite_factory() {
SK_DECLARE_STATIC_ONCE(once);
- SkOnce(&once, create_dwrite_factory, &gDWriteFactory, release_dwrite_factory);
+ SkOnce(&once, create_dwrite_factory, &gDWriteFactory);
return gDWriteFactory;
}