--- src/libGLESv2/global_state.cpp.orig +++ src/libGLESv2/global_state.cpp @@ -18,7 +18,7 @@ #include #if defined(ANGLE_PLATFORM_APPLE) -# include +# include #endif namespace egl { @@ -90,15 +90,22 @@ // cause excessive memory use. Temporarily avoid it by using pthread's thread local storage instead. // https://bugs.webkit.org/show_bug.cgi?id=228240 +namespace +{ +angle::TLSIndex g_CurrentThreadIndex = TLS_INVALID_INDEX; +pthread_once_t g_CurrentThreadIndexOnce = PTHREAD_ONCE_INIT; + +void InitCurrentThreadTLSIndex() +{ + ASSERT(g_CurrentThreadIndex == TLS_INVALID_INDEX); + g_CurrentThreadIndex = angle::CreateTLSIndex(nullptr); +} +} // anonymous namespace + static angle::TLSIndex GetCurrentThreadTLSIndex() { - static angle::TLSIndex CurrentThreadIndex = TLS_INVALID_INDEX; - static dispatch_once_t once; - dispatch_once(&once, ^{ - ASSERT(CurrentThreadIndex == TLS_INVALID_INDEX); - CurrentThreadIndex = angle::CreateTLSIndex(nullptr); - }); - return CurrentThreadIndex; + pthread_once(&g_CurrentThreadIndexOnce, InitCurrentThreadTLSIndex); + return g_CurrentThreadIndex; } Thread *GetCurrentThreadTLS() {