aboutsummaryrefslogtreecommitdiffstats
path: root/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp
diff options
context:
space:
mode:
authorDavid 'Digit' Turner <digit@google.com>2014-03-10 15:26:00 +0100
committerDavid 'Digit' Turner <digit@google.com>2014-03-11 18:02:57 +0100
commit47752bc9b62d974d82ba10bfc3633b72d10afcbd (patch)
treee5dbd1b3f20ff54654e6f5f2db2a0805431a7845 /emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp
parentaac93f1585bc9bdf8a57b6ed3c47c24f56a3990a (diff)
downloadsdk-47752bc9b62d974d82ba10bfc3633b72d10afcbd.zip
sdk-47752bc9b62d974d82ba10bfc3633b72d10afcbd.tar.gz
sdk-47752bc9b62d974d82ba10bfc3633b72d10afcbd.tar.bz2
emulator/opengl: Remove Android-specific thread_store.
This patch removes the use of the 'thread_store' class from <utils/threads.h> 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
Diffstat (limited to 'emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp')
-rw-r--r--emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp19
1 files changed, 15 insertions, 4 deletions
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());
}