From 41280abd1115c015f84c53ad15cc1b012dd19188 Mon Sep 17 00:00:00 2001 From: Haegeun Park Date: Wed, 10 Oct 2012 03:16:22 -0700 Subject: [PATCH] [Title] Added a threading module (using __thread) [Issue#] - [Problem] - [Cause] - [Solution] This module uses compiler specific Thread-Local-Variable (__thread) instead of pthread_getspecific(). To revert, needs makefile modification. --- CMakeLists.txt | 2 +- Makefile | 2 +- src/coregl_thread_pthread_and_gcc_tlv.c | 59 +++++++++++++++++++++++++++++++++ src/modules/fastpath/coregl_fastpath.c | 2 +- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/coregl_thread_pthread_and_gcc_tlv.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 068524a..eb72279 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ SET(CMAKE_SKIP_BUILD_RPATH TRUE) SET(COREGL "COREGL") SET(SRCS_common src/coregl.c - src/coregl_thread_pthread.c + src/coregl_thread_pthread_and_gcc_tlv.c src/coregl_trace.c src/coregl_export.c src/coregl_export_egl.c diff --git a/Makefile b/Makefile index a168876..6d06635 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,7 @@ LDFLAGS = -g -O2 -fvisibility=hidden -Wall -std=c99 -ldl -lpthread SOURCES = \ src/coregl.c \ - src/coregl_thread_pthread.c \ + src/coregl_thread_pthread_and_gcc_tlv.c \ src/coregl_trace.c \ src/coregl_export.c \ src/coregl_export_egl.c \ diff --git a/src/coregl_thread_pthread_and_gcc_tlv.c b/src/coregl_thread_pthread_and_gcc_tlv.c new file mode 100644 index 0000000..7092b8f --- /dev/null +++ b/src/coregl_thread_pthread_and_gcc_tlv.c @@ -0,0 +1,59 @@ +#include "coregl_internal.h" + +////////////////////////////////////////////////////////////////////////// +// Need implement this +int mutex_lock(Mutex *mt); +int mutex_unlock(Mutex *mt); +int get_current_thread(); +int set_current_thread_state(GLThreadState *tstate); +GLThreadState * get_current_thread_state(); +////////////////////////////////////////////////////////////////////////// + +static __thread GLThreadState *per_thread_state = NULL; + +int +mutex_lock(Mutex *mt) +{ + int ret = 0; + + if (pthread_mutex_lock(mt) == 0) + ret = 1; + else + ret = 0; + + return ret; +} + +int +mutex_unlock(Mutex *mt) +{ + int ret = 0; + + if (pthread_mutex_unlock(mt) == 0) + ret = 1; + else + ret = 0; + + return ret; +} + +int +get_current_thread() +{ + return pthread_self(); +} + +int +set_current_thread_state(GLThreadState *tstate) +{ + per_thread_state = tstate; + return 1; +} + +GLThreadState * +get_current_thread_state() +{ + return per_thread_state; +} + + diff --git a/src/modules/fastpath/coregl_fastpath.c b/src/modules/fastpath/coregl_fastpath.c index b5ccde6..f18eb06 100644 --- a/src/modules/fastpath/coregl_fastpath.c +++ b/src/modules/fastpath/coregl_fastpath.c @@ -885,7 +885,7 @@ extern void *tracepath_api_trace_end(const char *name, void *hint, int trace_tot int err = _orig_fastpath_glGetError(); \ if (err != GL_NO_ERROR) \ { \ - printf("\E[0;31;1mERROR(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \ + ERR("\E[0;31;1mERROR(GL %p) : %s returns GL error 0x%X\E[0m\n", oldctx->cstate, #func, err); \ goto finish; \ } \ } -- 2.7.4