--- src/libANGLE/Display.cpp 2026-01-07 08:40:27.000000000 +0800 +++ src/libANGLE/Display.cpp 2026-01-11 03:29:13.000000000 +0800 @@ -51,7 +51,7 @@ #include "libANGLE/trace.h" #if defined(ANGLE_PLATFORM_APPLE) -# include +# include # include "common/tls.h" #endif @@ -110,15 +110,22 @@ #if defined(ANGLE_PLATFORM_APPLE) // TODO(http://anglebug.com/42264979): Due to a bug in Apple's dyld loader, `thread_local` will // cause excessive memory use. Temporarily avoid it by using pthread's thread local storage instead. +namespace +{ +angle::TLSIndex g_DisplayIndex = TLS_INVALID_INDEX; +pthread_once_t g_DisplayIndexOnce = PTHREAD_ONCE_INIT; + +void InitDisplayTLSIndex() +{ + ASSERT(g_DisplayIndex == TLS_INVALID_INDEX); + g_DisplayIndex = angle::CreateTLSIndex(nullptr); +} +} // anonymous namespace + static angle::TLSIndex GetDisplayTLSIndex() { - static angle::TLSIndex DisplayIndex = TLS_INVALID_INDEX; - static dispatch_once_t once; - dispatch_once(&once, ^{ - ASSERT(DisplayIndex == TLS_INVALID_INDEX); - DisplayIndex = angle::CreateTLSIndex(nullptr); - }); - return DisplayIndex; + pthread_once(&g_DisplayIndexOnce, InitDisplayTLSIndex); + return g_DisplayIndex; } TLSData *GetDisplayTLS() {