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
#include "SkTArray.h"
#include "SkTypeface.h"
+struct SkBaseMutex;
+
/**
* \class SkFontConfigInterface
*
/**
* Return a singleton instance of a direct subclass that calls into
* libfontconfig. This does not affect the refcnt of the returned instance.
+ * The mutex may be used to guarantee the singleton is only constructed once.
*/
- static SkFontConfigInterface* GetSingletonDirectInterface();
+ static SkFontConfigInterface* GetSingletonDirectInterface(SkBaseMutex* mutex);
// New APIS, which have default impls for now (which do nothing)
return gFontConfigInterface;
}
-SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface() {
+SkFontConfigInterface* SkFontConfigInterface::GetSingletonDirectInterface(SkBaseMutex*) {
+ // Doesn't need passed-in mutex because getSingletonInterface() uses one
return getSingletonInterface();
}
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;
}
///////////////////////////////////////////////////////////////////////////////
if (fci) {
return fci;
}
- fci = SkFontConfigInterface::GetSingletonDirectInterface();
+ fci = SkFontConfigInterface::GetSingletonDirectInterface(&gFontConfigInterfaceMutex);
SkFontConfigInterface::SetGlobal(fci);
}
}