From af0b02f521d50f8cae1accf91d2c9d4a7e2a3c03 Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Fri, 6 Jun 2014 18:54:10 -0700 Subject: [PATCH] fix(util/thread_script_state): add a better workaround for clang++ bug Signed-off-by: Leonardo de Moura --- src/util/thread_script_state.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/util/thread_script_state.cpp b/src/util/thread_script_state.cpp index 3bf1a134a..dd7642a86 100644 --- a/src/util/thread_script_state.cpp +++ b/src/util/thread_script_state.cpp @@ -92,16 +92,18 @@ struct script_state_ref { ~script_state_ref() { recycle_state(m_state); } }; -// We should use std::unique_ptr, but clang++ 3.3.1 crashes when we use it. -std::shared_ptr LEAN_THREAD_LOCAL g_thread_state; +static std::unique_ptr & get_script_state_ref() { + static std::unique_ptr LEAN_THREAD_LOCAL g_thread_state; + if (!g_thread_state) + g_thread_state.reset(new script_state_ref()); + return g_thread_state; +} script_state get_thread_script_state() { - if (!g_thread_state) - g_thread_state = std::make_shared(); - return g_thread_state->m_state; + return get_script_state_ref()->m_state; } void release_thread_script_state() { - g_thread_state = nullptr; + get_script_state_ref().reset(nullptr); } }