1 #include "coregl_internal.h"
3 //////////////////////////////////////////////////////////////////////////
5 int mutex_init(Mutex *mt);
6 int mutex_lock(Mutex *mt);
7 int mutex_unlock(Mutex *mt);
8 int get_current_thread();
9 int set_current_thread_state(GLThreadState *tstate);
10 GLThreadState *get_current_thread_state();
11 //////////////////////////////////////////////////////////////////////////
13 static Mutex thread_key_mutex = MUTEX_INITIALIZER;
14 static int thread_key_inited = 0;
15 static pthread_key_t thread_key = 0;
22 if (pthread_mutex_init(mt, NULL) == 0)
35 if (pthread_mutex_lock(mt) == 0)
44 mutex_unlock(Mutex *mt)
48 if (pthread_mutex_unlock(mt) == 0)
59 return pthread_self();
63 set_current_thread_state(GLThreadState *tstate)
67 AST(mutex_lock(&thread_key_mutex) == 1);
69 if (thread_key_inited == 0) {
70 if (pthread_key_create(&thread_key, NULL) != 0) {
71 COREGL_ERR("Failed to create thread key.\n");
75 thread_key_inited = 1;
78 if (pthread_setspecific(thread_key, (void *)tstate) != 0) {
79 COREGL_ERR("Failed to set thread data.\n");
88 AST(mutex_unlock(&thread_key_mutex) == 1);
94 get_current_thread_state()
96 GLThreadState *ret = NULL;
98 if (thread_key_inited) {
99 ret = (GLThreadState *)pthread_getspecific(thread_key);