1 #include "coregl_internal.h"
3 //////////////////////////////////////////////////////////////////////////
5 int mutex_lock(Mutex *mt);
6 int mutex_unlock(Mutex *mt);
7 int get_current_thread();
8 int set_current_thread_state(GLThreadState *tstate);
9 GLThreadState * get_current_thread_state();
10 //////////////////////////////////////////////////////////////////////////
12 static Mutex thread_key_mutex = MUTEX_INITIALIZER;
13 static int thread_key_inited = 0;
14 static pthread_key_t thread_key = 0;
21 if (pthread_mutex_lock(mt) == 0)
30 mutex_unlock(Mutex *mt)
34 if (pthread_mutex_unlock(mt) == 0)
45 return pthread_self();
49 set_current_thread_state(GLThreadState *tstate)
53 AST(mutex_lock(&thread_key_mutex) == 1);
55 if (thread_key_inited == 0)
57 if (pthread_key_create(&thread_key, NULL) != 0)
59 ERR("Failed to create thread key.\n");
63 thread_key_inited = 1;
66 if (pthread_setspecific(thread_key, (void *)tstate) != 0)
68 ERR("Failed to set thread data.\n");
77 AST(mutex_unlock(&thread_key_mutex) == 1);
83 get_current_thread_state()
85 GLThreadState *ret = NULL;
86 if (thread_key_inited)
88 ret = (GLThreadState *)pthread_getspecific(thread_key);