From c18370bf9a1d3e7bbceaafda3b696190ee3d7cf6 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Tue, 28 Jan 2020 20:05:35 -0500 Subject: [PATCH] Workaround for Apple's clang not compiling thread_local correctly. --- src/context.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/context.cpp b/src/context.cpp index 33d24c6f..26f48217 100644 --- a/src/context.cpp +++ b/src/context.cpp @@ -45,15 +45,19 @@ Context::~Context() { } -static thread_local Context* context = NULL; +static thread_local Context* threadContext = NULL; Context* contextGet() { - assert(context); - return context; + assert(threadContext); + return threadContext; } +// Apple's clang incorrectly compiles this function when -O2 or higher is enabled. +#ifdef ARCH_MAC +__attribute__((optnone)) +#endif void contextSet(Context* context) { - rack::context = context; + threadContext = context; }