From 60b08a0adfe73f593af62c8d3f55958438360e1b Mon Sep 17 00:00:00 2001 From: tomhudson Date: Tue, 1 Jul 2014 08:06:14 -0700 Subject: Fix race condition in parallel font initialization. Uses a mutex to guard construction of the singleton, which initialies the non-threadsafe libfontconfig. Without this change, the parallel path ops test runner crashes 6/10 and hangs 2/10 on startup; with this change, 0/10 problems. BUG=skia:2693 R=mtklein@google.com, bungeman@google.com, reed@google.com, tomhudson@google.com Committed: https://skia.googlesource.com/skia/+/df022f5972ae6a2a1d96d15c50eca52cade3abd8 Author: tomhudson@chromium.org Review URL: https://codereview.chromium.org/355573006 --- src/ports/SkFontConfigInterface_direct.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/ports/SkFontConfigInterface_direct.cpp') diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp index dc9afbae1f..c0cfd8fdcf 100644 --- a/src/ports/SkFontConfigInterface_direct.cpp +++ b/src/ports/SkFontConfigInterface_direct.cpp @@ -124,9 +124,13 @@ private: SkMutex mutex_; }; -SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() { - SK_DECLARE_STATIC_LAZY_PTR(SkFontConfigInterfaceDirect, direct); - return direct.get(); +SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBaseMutex* mutex) { + SkAutoMutexAcquire ac(mutex); + static SkFontConfigInterfaceDirect* singleton = NULL; + if (singleton == NULL) { + singleton = SkNEW(SkFontConfigInterfaceDirect); + } + return singleton; } /////////////////////////////////////////////////////////////////////////////// -- cgit v1.2.3