diff options
Diffstat (limited to 'emulator/opengl/host')
3 files changed, 73 insertions, 35 deletions
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 <cutils/threads.h> +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<EglThreadInfo*>(value); } -} +}; + +} // namespace + +EglThreadInfo::EglThreadInfo() : + m_err(EGL_SUCCESS), m_api(EGL_OPENGL_ES_API) {} + +static emugl::LazyInstance<EglThreadInfoStore> s_tls = LAZY_INSTANCE_INIT; EglThreadInfo* EglThreadInfo::get(void) { - EglThreadInfo *ti = (EglThreadInfo *)thread_store_get(&s_tls); + EglThreadInfo *ti = static_cast<EglThreadInfo*>(s_tls->get()); if (!ti) { ti = new EglThreadInfo(); - thread_store_set(&s_tls, ti, tlsDestruct); + s_tls->set(ti); } return ti; } diff --git a/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp index 4f5d75f..1571b3a 100644 --- a/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp @@ -14,16 +14,47 @@ * limitations under the License. */ -#include <stdio.h> #include "ThreadInfo.h" -//#define TRACE_THREADINFO -#ifdef TRACE_THREADINFO +#include "emugl/common/lazy_instance.h" +#include "emugl/common/thread_store.h" + +#include <stdio.h> + +// Set TRACE_THREADINFO to 1 to debug creation/destruction of ThreadInfo +// instances. +#define TRACE_THREADINFO 0 + +#if TRACE_THREADINFO #define LOG_THREADINFO(x...) fprintf(stderr, x) #else #define LOG_THREADINFO(x...) #endif +namespace { + +class ThreadInfoStore : public ::emugl::ThreadStore { +public: + ThreadInfoStore() : ::emugl::ThreadStore(&destructor) {} + + size_t getInstanceCount() const { return mNumInstances; } + +private: + static void destructor(void* value) { + LOG_THREADINFO("%s: EFL %p (%d instances)\n", __FUNCTION__, + value, mNumInstances); + delete static_cast<ThreadInfo*>(value); + mNumInstances--; + } + + static size_t mNumInstances; +}; + +size_t ThreadInfoStore::mNumInstances = 0; + +} // namespace + + void ThreadInfo::updateInfo(ContextPtr eglCtx, EglDisplay* dpy, GLEScontext* glesCtx, @@ -37,27 +68,16 @@ void ThreadInfo::updateInfo(ContextPtr eglCtx, objManager = manager; } -#include <cutils/threads.h> -static thread_store_t s_tls = THREAD_STORE_INITIALIZER; -static int active_instance = 0; -static void tlsDestruct(void *ptr) -{ - active_instance--; - LOG_THREADINFO("tlsDestruct EGL %lx %d\n", (long)ptr, active_instance); - if (ptr) { - ThreadInfo *ti = (ThreadInfo *)ptr; - delete ti; - } -} +static ::emugl::LazyInstance<ThreadInfoStore> s_tls = LAZY_INSTANCE_INIT; ThreadInfo *getThreadInfo() { - ThreadInfo *ti = (ThreadInfo *)thread_store_get(&s_tls); + ThreadInfo *ti = static_cast<ThreadInfo*>(s_tls->get()); if (!ti) { ti = new ThreadInfo(); - thread_store_set(&s_tls, ti, tlsDestruct); - active_instance++; - LOG_THREADINFO("getThreadInfo EGL %lx %d\n", (long)ti, active_instance); + s_tls->set(ti); + LOG_THREADINFO("%s: EGL %p (%d instances)\n", __FUNCTION__, + ti, (int)ThreadInfoStore::getInstanceCount()); } return ti; } diff --git a/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp index 566ca40..5337009 100644 --- a/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp +++ b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp @@ -15,17 +15,28 @@ */ #include "ThreadInfo.h" -#include <cutils/threads.h> +#include "emugl/common/lazy_instance.h" +#include "emugl/common/thread_store.h" -static thread_store_t s_tls = THREAD_STORE_INITIALIZER; +namespace { + +class ThreadInfoStore : public ::emugl::ThreadStore { +public: + ThreadInfoStore() : ::emugl::ThreadStore(NULL) {} +}; + +} // namespace + +static ::emugl::LazyInstance<ThreadInfoStore> s_tls = LAZY_INSTANCE_INIT; RenderThreadInfo::RenderThreadInfo() { - thread_store_set(&s_tls, this, NULL); + s_tls->set(this); } RenderThreadInfo::~RenderThreadInfo() { + s_tls->set(NULL); } RenderThreadInfo* RenderThreadInfo::get() { - return (RenderThreadInfo*)thread_store_get(&s_tls); + return static_cast<RenderThreadInfo*>(s_tls->get()); } |
