From 29b86f9852b2b7ecc31cdfee56679537e40bc6e2 Mon Sep 17 00:00:00 2001 From: marha Date: Mon, 12 Apr 2010 09:53:17 +0000 Subject: svn merge -r524:HEAD "^/branches/released" . --- mesalib/src/mesa/glapi/glthread.h | 162 ++++++++++---------------------------- 1 file changed, 42 insertions(+), 120 deletions(-) (limited to 'mesalib/src/mesa/glapi/glthread.h') diff --git a/mesalib/src/mesa/glapi/glthread.h b/mesalib/src/mesa/glapi/glthread.h index 8ec933a85..4fe99284a 100644 --- a/mesalib/src/mesa/glapi/glthread.h +++ b/mesalib/src/mesa/glapi/glthread.h @@ -64,21 +64,12 @@ #define GLTHREAD_H -#if defined(USE_MGL_NAMESPACE) -#define _glapi_Dispatch _mglapi_Dispatch +#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS) +#ifndef THREADS +#define THREADS #endif - - - -#if (defined(PTHREADS) || defined(SOLARIS_THREADS) ||\ - defined(WIN32_THREADS) || defined(BEOS_THREADS)) \ - && !defined(THREADS) -# define THREADS #endif -#ifdef VMS -#include -#endif /* * POSIX threads. This should be your choice in the Unix world @@ -116,80 +107,7 @@ typedef pthread_mutex_t _glthread_Mutex; #define _glthread_UNLOCK_MUTEX(name) \ (void) pthread_mutex_unlock(&(name)) -typedef pthread_cond_t _glthread_Cond; - -#define _glthread_DECLARE_STATIC_COND(name) \ - static _glthread_Cond name = PTHREAD_COND_INITIALIZER - -#define _glthread_INIT_COND(cond) \ - pthread_cond_init(&(cond), NULL) - -#define _glthread_DESTROY_COND(name) \ - pthread_cond_destroy(&(name)) - -#define _glthread_COND_WAIT(cond, mutex) \ - pthread_cond_wait(&(cond), &(mutex)) - -#define _glthread_COND_SIGNAL(cond) \ - pthread_cond_signal(&(cond)) - -#define _glthread_COND_BROADCAST(cond) \ - pthread_cond_broadcast(&(cond)) - - -#else /* PTHREADS */ - -typedef unsigned int _glthread_Cond; -#define _glthread_DECLARE_STATIC_COND(name) \ -// #warning Condition variables not implemented. - -#define _glthread_INIT_COND(cond) \ - ASSERT(0); - -#define _glthread_DESTROY_COND(name) \ - ASSERT(0); - -#define _glthread_COND_WAIT(cond, mutex) \ - ASSERT(0); - -#define _glthread_COND_SIGNAL(cond) \ - ASSERT(0); - -#define _glthread_COND_BROADCAST(cond) \ - ASSERT(0); - -#endif - - -/* - * Solaris threads. Use only up to Solaris 2.4. - * Solaris 2.5 and higher provide POSIX threads. - * Be sure to compile with -mt on the Solaris compilers, or - * use -D_REENTRANT if using gcc. - */ -#ifdef SOLARIS_THREADS -#include - -typedef struct { - thread_key_t key; - mutex_t keylock; - int initMagic; -} _glthread_TSD; - -typedef thread_t _glthread_Thread; - -typedef mutex_t _glthread_Mutex; - -/* XXX need to really implement mutex-related macros */ -#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0 -#define _glthread_INIT_MUTEX(name) (void) name -#define _glthread_DESTROY_MUTEX(name) (void) name -#define _glthread_LOCK_MUTEX(name) (void) name -#define _glthread_UNLOCK_MUTEX(name) (void) name - -#endif /* SOLARIS_THREADS */ - - +#endif /* PTHREADS */ /* @@ -209,11 +127,20 @@ typedef HANDLE _glthread_Thread; typedef CRITICAL_SECTION _glthread_Mutex; -#define _glthread_DECLARE_STATIC_MUTEX(name) /*static*/ _glthread_Mutex name = {0,0,0,0,0,0} -#define _glthread_INIT_MUTEX(name) InitializeCriticalSection(&name) -#define _glthread_DESTROY_MUTEX(name) DeleteCriticalSection(&name) -#define _glthread_LOCK_MUTEX(name) EnterCriticalSection(&name) -#define _glthread_UNLOCK_MUTEX(name) LeaveCriticalSection(&name) +#define _glthread_DECLARE_STATIC_MUTEX(name) \ + /* static */ _glthread_Mutex name = { 0, 0, 0, 0, 0, 0 } + +#define _glthread_INIT_MUTEX(name) \ + InitializeCriticalSection(&name) + +#define _glthread_DESTROY_MUTEX(name) \ + DeleteCriticalSection(&name) + +#define _glthread_LOCK_MUTEX(name) \ + EnterCriticalSection(&name) + +#define _glthread_UNLOCK_MUTEX(name) \ + LeaveCriticalSection(&name) #endif /* WIN32_THREADS */ @@ -252,22 +179,34 @@ typedef struct { } benaphore; typedef benaphore _glthread_Mutex; -#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = { 0, 0 } -#define _glthread_INIT_MUTEX(name) name.sem = create_sem(0, #name"_benaphore"), name.lock = 0 -#define _glthread_DESTROY_MUTEX(name) delete_sem(name.sem), name.lock = 0 -#define _glthread_LOCK_MUTEX(name) if (name.sem == 0) _glthread_INIT_MUTEX(name); \ - if (atomic_add(&(name.lock), 1) >= 1) acquire_sem(name.sem) -#define _glthread_UNLOCK_MUTEX(name) if (atomic_add(&(name.lock), -1) > 1) release_sem(name.sem) +#define _glthread_DECLARE_STATIC_MUTEX(name) \ + static _glthread_Mutex name = { 0, 0 } -#endif /* BEOS_THREADS */ +#define _glthread_INIT_MUTEX(name) \ + name.sem = create_sem(0, #name"_benaphore"), \ + name.lock = 0 +#define _glthread_DESTROY_MUTEX(name) \ + delete_sem(name.sem), \ + name.lock = 0 +#define _glthread_LOCK_MUTEX(name) \ + if (name.sem == 0) \ + _glthread_INIT_MUTEX(name); \ + if (atomic_add(&(name.lock), 1) >= 1) \ + acquire_sem(name.sem) + +#define _glthread_UNLOCK_MUTEX(name) \ + if (atomic_add(&(name.lock), -1) > 1) \ + release_sem(name.sem) + +#endif /* BEOS_THREADS */ -#ifndef THREADS /* * THREADS not defined */ +#ifndef THREADS typedef unsigned _glthread_TSD; @@ -301,6 +240,10 @@ extern void _glthread_InitTSD(_glthread_TSD *); +extern void +_glthread_DestroyTSD(_glthread_TSD *); /* WIN32 only */ + + extern void * _glthread_GetTSD(_glthread_TSD *); @@ -308,26 +251,5 @@ _glthread_GetTSD(_glthread_TSD *); extern void _glthread_SetTSD(_glthread_TSD *, void *); -#if !defined __GNUC__ || __GNUC__ < 3 -# define __builtin_expect(x, y) x -#endif - -#if defined(GLX_USE_TLS) - -extern __thread struct _glapi_table * _glapi_tls_Dispatch - __attribute__((tls_model("initial-exec"))); - -#define GET_DISPATCH() _glapi_tls_Dispatch - -#elif !defined(GL_CALL) -# if defined(THREADS) -# define GET_DISPATCH() \ - ((__builtin_expect( _glapi_Dispatch != NULL, 1 )) \ - ? _glapi_Dispatch : _glapi_get_dispatch()) -# else -# define GET_DISPATCH() _glapi_Dispatch -# endif /* defined(THREADS) */ -#endif /* ndef GL_CALL */ - #endif /* THREADS_H */ -- cgit v1.2.3