From 1b81877880253c75f835eede9a8ee21b9e7b584a Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 2 Jun 2014 11:26:59 -0700 Subject: 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 --- src/ports/SkGlobalInitialization_chromium.cpp | 5 ++--- src/ports/SkGlobalInitialization_default.cpp | 5 ++--- src/utils/SkEventTracer.cpp | 19 +++++++++---------- src/utils/win/SkDWrite.cpp | 14 ++++++++------ 4 files changed, 21 insertions(+), 22 deletions(-) (limited to 'src') diff --git a/src/ports/SkGlobalInitialization_chromium.cpp b/src/ports/SkGlobalInitialization_chromium.cpp index 37e5450e19..f42b272f18 100644 --- a/src/ports/SkGlobalInitialization_chromium.cpp +++ b/src/ports/SkGlobalInitialization_chromium.cpp @@ -62,7 +62,7 @@ #include "SkMatrixImageFilter.h" #include "SkXfermodeImageFilter.h" -static void InitializeFlattenables(int*) { +static void InitializeFlattenables() { SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAvoidXfermode) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBicubicImageFilter) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapProcShader) @@ -122,7 +122,6 @@ static void InitializeFlattenables(int*) { } void SkFlattenable::InitializeFlattenablesIfNeeded() { - int dummy; SK_DECLARE_STATIC_ONCE(once); - SkOnce(&once, InitializeFlattenables, &dummy); + SkOnce(&once, InitializeFlattenables); } diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp index 949decd018..ce42ca5aad 100644 --- a/src/ports/SkGlobalInitialization_default.cpp +++ b/src/ports/SkGlobalInitialization_default.cpp @@ -62,7 +62,7 @@ #include "SkMatrixImageFilter.h" #include "SkXfermodeImageFilter.h" -static void InitializeFlattenables(int*) { +static void InitializeFlattenables() { SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkAvoidXfermode) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBicubicImageFilter) SK_DEFINE_FLATTENABLE_REGISTRAR_ENTRY(SkBitmapProcShader) @@ -123,7 +123,6 @@ static void InitializeFlattenables(int*) { } void SkFlattenable::InitializeFlattenablesIfNeeded() { - int dummy; SK_DECLARE_STATIC_ONCE(once); - SkOnce(&once, InitializeFlattenables, &dummy); + SkOnce(&once, InitializeFlattenables); } diff --git a/src/utils/SkEventTracer.cpp b/src/utils/SkEventTracer.cpp index 529fca3519..65e8372395 100644 --- a/src/utils/SkEventTracer.cpp +++ b/src/utils/SkEventTracer.cpp @@ -36,25 +36,24 @@ class SkDefaultEventTracer: public SkEventTracer { }; }; -SkEventTracer *SkEventTracer::gInstance; +SkEventTracer* SkEventTracer::gInstance; -static void intialiize_default_tracer(void *current_instance) { +static void cleanup_tracer() { + // calling SetInstance will delete the existing instance. + SkEventTracer::SetInstance(NULL); +} + +static void intialize_default_tracer(SkEventTracer* current_instance) { if (NULL == current_instance) { SkEventTracer::SetInstance(SkNEW(SkDefaultEventTracer)); } + atexit(cleanup_tracer); } -static void cleanup_tracer() { - // calling SetInstance will delete the existing instance. - SkEventTracer::SetInstance(NULL); -} SkEventTracer* SkEventTracer::GetInstance() { SK_DECLARE_STATIC_ONCE(once); - SkOnce(&once, - intialiize_default_tracer, - SkEventTracer::gInstance, - cleanup_tracer); + SkOnce(&once, intialize_default_tracer, SkEventTracer::gInstance); SkASSERT(NULL != SkEventTracer::gInstance); return SkEventTracer::gInstance; } diff --git a/src/utils/win/SkDWrite.cpp b/src/utils/win/SkDWrite.cpp index 16e8ddc4d0..87826b5194 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( @@ -31,17 +37,13 @@ static void create_dwrite_factory(IDWriteFactory** factory) { __uuidof(IDWriteFactory), reinterpret_cast(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; } -- cgit v1.2.3