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)
71 if (pthread_key_create(&thread_key, NULL) != 0)
73 COREGL_ERR("Failed to create thread key.\n");
77 thread_key_inited = 1;
80 if (pthread_setspecific(thread_key, (void *)tstate) != 0)
82 COREGL_ERR("Failed to set thread data.\n");
91 AST(mutex_unlock(&thread_key_mutex) == 1);
97 get_current_thread_state()
99 GLThreadState *ret = NULL;
101 if (thread_key_inited)
103 ret = (GLThreadState *)pthread_getspecific(thread_key);