diff options
author | keunyoung <keunyoung@google.com> | 2013-04-04 18:40:27 -0700 |
---|---|---|
committer | keunyoung <keunyoung@google.com> | 2013-04-05 12:52:38 -0700 |
commit | 2cab88d5153a1965f5a5bbd43982de992c617828 (patch) | |
tree | 54ffb8574f3c1d02b46a9b1fc625447b30fb502b /emulator | |
parent | 3a8b15d324e47a79207fde2ec10d91024333fe55 (diff) | |
download | sdk-2cab88d5153a1965f5a5bbd43982de992c617828.zip sdk-2cab88d5153a1965f5a5bbd43982de992c617828.tar.gz sdk-2cab88d5153a1965f5a5bbd43982de992c617828.tar.bz2 |
use tlsDestruct in linux to destroy thread specific OpenGl resources
- lack of tlsDestruct causes resource leakage in linux
Change-Id: I6f5308fd00da06dbecd9246393021e3d72aa40c3
Diffstat (limited to 'emulator')
-rw-r--r-- | emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp | 28 | ||||
-rw-r--r-- | emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp | 24 |
2 files changed, 23 insertions, 29 deletions
diff --git a/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp index d1d018f..4f5d75f 100644 --- a/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp +++ b/emulator/opengl/host/libs/Translator/EGL/ThreadInfo.cpp @@ -14,8 +14,15 @@ * limitations under the License. */ +#include <stdio.h> #include "ThreadInfo.h" +//#define TRACE_THREADINFO +#ifdef TRACE_THREADINFO +#define LOG_THREADINFO(x...) fprintf(stderr, x) +#else +#define LOG_THREADINFO(x...) +#endif void ThreadInfo::updateInfo(ContextPtr eglCtx, EglDisplay* dpy, @@ -30,24 +37,13 @@ void ThreadInfo::updateInfo(ContextPtr eglCtx, objManager = manager; } -#ifdef __linux__ - -__thread ThreadInfo* thread = NULL; - -ThreadInfo* getThreadInfo(){ - if(!thread) { - thread = new ThreadInfo(); - } - return thread; -} - -#else - #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; @@ -60,8 +56,8 @@ ThreadInfo *getThreadInfo() 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); } return ti; } - -#endif diff --git a/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp index 2f2a962..82be7b9 100644 --- a/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp +++ b/emulator/opengl/host/libs/libOpenglRender/ThreadInfo.cpp @@ -13,27 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#include <stdio.h> #include "ThreadInfo.h" -#ifdef __linux__ - -static __thread RenderThreadInfo *tinfo = NULL; - -RenderThreadInfo *getRenderThreadInfo() -{ - if (!tinfo) { - tinfo = new RenderThreadInfo(); - } - return tinfo; -} - +//#define TRACE_THREADINFO +#ifdef TRACE_THREADINFO +#define LOG_THREADINFO(x...) fprintf(stderr, x) #else +#define LOG_THREADINFO(x...) +#endif #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 Render %lx %d\n", (long)ptr, active_instance); if (ptr) { RenderThreadInfo *ti = (RenderThreadInfo *)ptr; delete ti; @@ -46,8 +43,9 @@ RenderThreadInfo *getRenderThreadInfo() if (!ti) { ti = new RenderThreadInfo(); thread_store_set(&s_tls, ti, tlsDestruct); + active_instance++; + LOG_THREADINFO("getRenderThreadInfo %lx %d\n", (long)ti, active_instance); } return ti; } -#endif |