Avoid using global Mutex variables (#1252)

After 5c9815f, some Mutexes are used as global C++ variables which are loaded before main(). Since the Mutex constructor checks for unfair lock experiment, it triggers an experiment configuration load, and our app isn't ready to respond that early in the process.
This commit is contained in:
Huy Nguyen
2018-11-26 17:25:38 -08:00
committed by GitHub
parent f2bc63f05a
commit a255953d34
4 changed files with 27 additions and 11 deletions

View File

@@ -34,9 +34,13 @@
{
if (self = [super init]) {
static dispatch_once_t onceToken;
static ASDN::Mutex *mutex;
dispatch_once(&onceToken, ^{
mutex = new ASDN::Mutex();
});
// Concurrently initialising TextKit components crashes (rdar://18448377) so we use a global lock.
// Allocate mutex on the heap to prevent destruction at app exit (https://github.com/TextureGroup/Texture/issues/136)
static auto *mutex = new ASDN::Mutex;
ASDN::MutexLocker l(*mutex);
__instanceLock__ = std::make_shared<ASDN::Mutex>();