From 47752bc9b62d974d82ba10bfc3633b72d10afcbd Mon Sep 17 00:00:00 2001 From: David 'Digit' Turner Date: Mon, 10 Mar 2014 15:26:00 +0100 Subject: emulator/opengl: Remove Android-specific thread_store. This patch removes the use of the 'thread_store' class from by providing its own implementation instead under shared/emugl/common/thread_store.h, plus appropriate unit tests. Note that unlike the Android version, this properly destroys the thread-local values on thread exit (instead of leaking them). + Provide a LazyInstance class used to perform thread-safe lazy initialization of static variables without the use of C++ constructors. Change-Id: Iabe01fbd713c6872b5fe245d7255c3c03749a88a --- .../host/libs/Translator/EGL/EglThreadInfo.cpp | 31 +++++++++++++--------- 1 file changed, 19 insertions(+), 12 deletions(-) (limited to 'emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp') diff --git a/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp index 1b403f2..6481774 100644 --- a/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/EglThreadInfo.cpp @@ -16,26 +16,33 @@ #include "EglThreadInfo.h" #include "EglOsApi.h" -EglThreadInfo::EglThreadInfo():m_err(EGL_SUCCESS),m_api(EGL_OPENGL_ES_API) {} +#include "emugl/common/lazy_instance.h" +#include "emugl/common/thread_store.h" -#include +namespace { -static thread_store_t s_tls = THREAD_STORE_INITIALIZER; - -static void tlsDestruct(void *ptr) -{ - if (ptr) { - EglThreadInfo *ti = (EglThreadInfo *)ptr; - delete ti; +class EglThreadInfoStore : public emugl::ThreadStore { +public: + EglThreadInfoStore() : emugl::ThreadStore(&destructor) {} +private: + static void destructor(void* value) { + delete static_cast(value); } -} +}; + +} // namespace + +EglThreadInfo::EglThreadInfo() : + m_err(EGL_SUCCESS), m_api(EGL_OPENGL_ES_API) {} + +static emugl::LazyInstance s_tls = LAZY_INSTANCE_INIT; EglThreadInfo* EglThreadInfo::get(void) { - EglThreadInfo *ti = (EglThreadInfo *)thread_store_get(&s_tls); + EglThreadInfo *ti = static_cast(s_tls->get()); if (!ti) { ti = new EglThreadInfo(); - thread_store_set(&s_tls, ti, tlsDestruct); + s_tls->set(ti); } return ti; } -- cgit v1.1