From a4ec52f245746b477b673e7cfb9b73d711bfa0d6 Mon Sep 17 00:00:00 2001
From: George Sapountzis
Date: Fri, 26 Feb 2010 20:58:24 +0200
Subject: glapi.h: consolidate GET_DISPATCH() and GET_CURRENT_CONTEXT() macros
Use likely() macro, as this is what most projects use.
Drops GL_CALL define, cannot find it in mesa tree.
Also, whitespace cleaunps in glthread.h
---
src/mesa/glapi/glthread.h | 85 ++++++++++++++++++++++-------------------------
1 file changed, 39 insertions(+), 46 deletions(-)
(limited to 'src/mesa/glapi/glthread.h')
diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h
index 8ec933a851..be39501395 100644
--- a/src/mesa/glapi/glthread.h
+++ b/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(SOLARIS_THREADS) || 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
@@ -121,7 +112,7 @@ typedef pthread_cond_t _glthread_Cond;
#define _glthread_DECLARE_STATIC_COND(name) \
static _glthread_Cond name = PTHREAD_COND_INITIALIZER
-#define _glthread_INIT_COND(cond) \
+#define _glthread_INIT_COND(cond) \
pthread_cond_init(&(cond), NULL)
#define _glthread_DESTROY_COND(name) \
@@ -143,7 +134,7 @@ typedef unsigned int _glthread_Cond;
#define _glthread_DECLARE_STATIC_COND(name) \
// #warning Condition variables not implemented.
-#define _glthread_INIT_COND(cond) \
+#define _glthread_INIT_COND(cond) \
ASSERT(0);
#define _glthread_DESTROY_COND(name) \
@@ -209,11 +200,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,12 +252,26 @@ 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 }
+
+#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 */
@@ -308,26 +322,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
From d41ab94d35cb47effbd2582289298be4f13c50e4 Mon Sep 17 00:00:00 2001
From: George Sapountzis
Date: Mon, 1 Mar 2010 04:44:02 +0200
Subject: glapi.c: misc coscmetic for FreeTSD
- move out of of the dispatch/context block to after corresponding init functions
- use more consistent naming with corresponding init functions
- XXX use _glthread_InitTSD() vs (void)_glthread_GetTSD() in _glapi_check_multithread() XXX
---
src/gallium/state_trackers/wgl/stw_device.c | 4 ++--
src/mesa/glapi/glapi.c | 35 +++++++++++++++++++----------
src/mesa/glapi/glapi.h | 8 +++++++
src/mesa/glapi/glthread.c | 23 ++++++++++---------
src/mesa/glapi/glthread.h | 4 ++++
5 files changed, 50 insertions(+), 24 deletions(-)
(limited to 'src/mesa/glapi/glthread.h')
diff --git a/src/gallium/state_trackers/wgl/stw_device.c b/src/gallium/state_trackers/wgl/stw_device.c
index e5fa6ac8eb..472a2a5379 100644
--- a/src/gallium/state_trackers/wgl/stw_device.c
+++ b/src/gallium/state_trackers/wgl/stw_device.c
@@ -47,7 +47,6 @@
#ifdef WIN32_THREADS
extern _glthread_Mutex OneTimeLock;
-extern void FreeAllTSD(void);
#endif
@@ -183,7 +182,8 @@ stw_cleanup(void)
#ifdef WIN32_THREADS
_glthread_DESTROY_MUTEX(OneTimeLock);
- FreeAllTSD();
+
+ _glapi_destroy_multithread();
#endif
#ifdef DEBUG
diff --git a/src/mesa/glapi/glapi.c b/src/mesa/glapi/glapi.c
index fe523073ca..056abd7233 100644
--- a/src/mesa/glapi/glapi.c
+++ b/src/mesa/glapi/glapi.c
@@ -118,15 +118,6 @@ _glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */
static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
-#if defined(WIN32_THREADS)
-void FreeTSD(_glthread_TSD *p);
-void FreeAllTSD(void)
-{
- FreeTSD(&_gl_DispatchTSD);
- FreeTSD(&ContextTSD);
-}
-#endif /* defined(WIN32_THREADS) */
-
#endif /* defined(THREADS) */
PUBLIC struct _glapi_table *_glapi_Dispatch = (struct _glapi_table *) __glapi_noop_table;
@@ -140,6 +131,22 @@ PUBLIC void *_glapi_Context = NULL;
#if defined(THREADS) && !defined(GLX_USE_TLS)
+void
+_glapi_init_multithread(void)
+{
+ _glthread_InitTSD(&_gl_DispatchTSD);
+ _glthread_InitTSD(&ContextTSD);
+}
+
+void
+_glapi_destroy_multithread(void)
+{
+#ifdef WIN32_THREADS
+ _glthread_DestroyTSD(&_gl_DispatchTSD);
+ _glthread_DestroyTSD(&ContextTSD);
+#endif
+}
+
/**
* Mutex for multithread check.
*/
@@ -168,9 +175,7 @@ _glapi_check_multithread(void)
CHECK_MULTITHREAD_LOCK();
if (firstCall) {
- /* initialize TSDs */
- (void) _glthread_GetTSD(&ContextTSD);
- (void) _glthread_GetTSD(&_gl_DispatchTSD);
+ _glapi_init_multithread(void)
knownID = _glthread_GetID();
firstCall = GL_FALSE;
@@ -185,6 +190,12 @@ _glapi_check_multithread(void)
#else
+void
+_glapi_init_multithread(void) { }
+
+void
+_glapi_destroy_multithread(void) { }
+
PUBLIC void
_glapi_check_multithread(void) { }
diff --git a/src/mesa/glapi/glapi.h b/src/mesa/glapi/glapi.h
index 0abec5df76..2eae6d5c43 100644
--- a/src/mesa/glapi/glapi.h
+++ b/src/mesa/glapi/glapi.h
@@ -121,6 +121,14 @@ extern void *_glapi_Context;
** GL API public functions
**/
+extern void
+_glapi_init_multithread(void);
+
+
+extern void
+_glapi_destroy_multithread(void);
+
+
extern void
_glapi_check_multithread(void);
diff --git a/src/mesa/glapi/glthread.c b/src/mesa/glapi/glthread.c
index be4e2f754d..15401d730e 100644
--- a/src/mesa/glapi/glthread.c
+++ b/src/mesa/glapi/glthread.c
@@ -190,17 +190,9 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
*/
#ifdef WIN32_THREADS
-void FreeTSD(_glthread_TSD *p)
+static void InsteadOf_exit(int nCode)
{
- if (p->initMagic==INIT_MAGIC) {
- TlsFree(p->key);
- p->initMagic=0;
- }
-}
-
-void InsteadOf_exit(int nCode)
-{
- DWORD dwErr=GetLastError();
+ DWORD dwErr = GetLastError();
}
PUBLIC unsigned long
@@ -222,6 +214,17 @@ _glthread_InitTSD(_glthread_TSD *tsd)
}
+void
+_glthread_DestroyTSD(_glthread_TSD *tsd)
+{
+ if (tsd->initMagic != INIT_MAGIC) {
+ return;
+ }
+ TlsFree(tsd->key);
+ tsd->initMagic = 0x0;
+}
+
+
void *
_glthread_GetTSD(_glthread_TSD *tsd)
{
diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h
index be39501395..389c24204b 100644
--- a/src/mesa/glapi/glthread.h
+++ b/src/mesa/glapi/glthread.h
@@ -315,6 +315,10 @@ extern void
_glthread_InitTSD(_glthread_TSD *);
+extern void
+_glthread_DestroyTSD(_glthread_TSD *); /* WIN32 only */
+
+
extern void *
_glthread_GetTSD(_glthread_TSD *);
--
cgit v1.2.3
From d7e6e879fdfb1a4e3125237d117f68025dfa0d72 Mon Sep 17 00:00:00 2001
From: George Sapountzis
Date: Mon, 1 Mar 2010 17:28:55 +0200
Subject: glapi: drop SOLARIS_THREADS
It seems that SOLARIS_THREADS is not used and does not work.
---
docs/dispatch.html | 2 +-
src/mesa/glapi/gen/gl_x86-64_asm.py | 2 +-
src/mesa/glapi/gen/gl_x86_asm.py | 2 +-
src/mesa/glapi/glthread.c | 68 -------------------------------------
src/mesa/glapi/glthread.h | 35 ++-----------------
src/mesa/x86-64/glapi_x86-64.S | 2 +-
src/mesa/x86/glapi_x86.S | 2 +-
7 files changed, 7 insertions(+), 106 deletions(-)
(limited to 'src/mesa/glapi/glthread.h')
diff --git a/docs/dispatch.html b/docs/dispatch.html
index 0c54a84675..e5587c1a29 100644
--- a/docs/dispatch.html
+++ b/docs/dispatch.html
@@ -199,7 +199,7 @@ few preprocessor defines.
If GLX_USE_TLS is defined, method #4 is used.
If PTHREADS is defined, method #3 is used.
If any of PTHREADS,
-SOLARIS_THREADS, WIN32_THREADS, or BEOS_THREADS
+WIN32_THREADS, or BEOS_THREADS
is defined, method #2 is used.
If none of the preceeding are defined, method #1 is used.
diff --git a/src/mesa/glapi/gen/gl_x86-64_asm.py b/src/mesa/glapi/gen/gl_x86-64_asm.py
index 31c1a2b93a..8ac57ab7eb 100644
--- a/src/mesa/glapi/gen/gl_x86-64_asm.py
+++ b/src/mesa/glapi/gen/gl_x86-64_asm.py
@@ -138,7 +138,7 @@ class PrintGenericStubs(gl_XML.gl_print_base):
print '# define GL_PREFIX(n) GLNAME(CONCAT(gl,n))'
print '# endif'
print ''
- print '#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
+ print '#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
print '# define THREADS'
print '#endif'
print ''
diff --git a/src/mesa/glapi/gen/gl_x86_asm.py b/src/mesa/glapi/gen/gl_x86_asm.py
index d210f3a248..a48724ee61 100644
--- a/src/mesa/glapi/gen/gl_x86_asm.py
+++ b/src/mesa/glapi/gen/gl_x86_asm.py
@@ -79,7 +79,7 @@ class PrintGenericStubs(gl_XML.gl_print_base):
print '#define GLOBL_FN(x) GLOBL x'
print '#endif'
print ''
- print '#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
+ print '#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)'
print '# define THREADS'
print '#endif'
print ''
diff --git a/src/mesa/glapi/glthread.c b/src/mesa/glapi/glthread.c
index 15401d730e..17b6bb2b6a 100644
--- a/src/mesa/glapi/glthread.c
+++ b/src/mesa/glapi/glthread.c
@@ -115,74 +115,6 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
-/*
- * Solaris/Unix International Threads -- Use only if POSIX threads
- * aren't available on your Unix platform. Solaris 2.[34] are examples
- * of platforms where this is the case. Be sure to use -mt and/or
- * -D_REENTRANT when compiling.
- */
-#ifdef SOLARIS_THREADS
-#define USE_LOCK_FOR_KEY /* undef this to try a version without
- lock for the global key... */
-
-PUBLIC unsigned long
-_glthread_GetID(void)
-{
- abort(); /* XXX not implemented yet */
- return (unsigned long) 0;
-}
-
-
-void
-_glthread_InitTSD(_glthread_TSD *tsd)
-{
- if ((errno = mutex_init(&tsd->keylock, 0, NULL)) != 0 ||
- (errno = thr_keycreate(&(tsd->key), free)) != 0) {
- perror(INIT_TSD_ERROR);
- exit(-1);
- }
- tsd->initMagic = INIT_MAGIC;
-}
-
-
-void *
-_glthread_GetTSD(_glthread_TSD *tsd)
-{
- void* ret;
- if (tsd->initMagic != INIT_MAGIC) {
- _glthread_InitTSD(tsd);
- }
-#ifdef USE_LOCK_FOR_KEY
- mutex_lock(&tsd->keylock);
- thr_getspecific(tsd->key, &ret);
- mutex_unlock(&tsd->keylock);
-#else
- if ((errno = thr_getspecific(tsd->key, &ret)) != 0) {
- perror(GET_TSD_ERROR);
- exit(-1);
- }
-#endif
- return ret;
-}
-
-
-void
-_glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
-{
- if (tsd->initMagic != INIT_MAGIC) {
- _glthread_InitTSD(tsd);
- }
- if ((errno = thr_setspecific(tsd->key, ptr)) != 0) {
- perror(SET_TSD_ERROR);
- exit(-1);
- }
-}
-
-#undef USE_LOCK_FOR_KEY
-#endif /* SOLARIS_THREADS */
-
-
-
/*
* Win32 Threads. The only available option for Windows 95/NT.
* Be sure that you compile using the Multithreaded runtime, otherwise
diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h
index 389c24204b..e5193aaf98 100644
--- a/src/mesa/glapi/glthread.h
+++ b/src/mesa/glapi/glthread.h
@@ -64,7 +64,7 @@
#define GLTHREAD_H
-#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
+#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
#ifndef THREADS
#define THREADS
#endif
@@ -149,38 +149,7 @@ typedef unsigned int _glthread_Cond;
#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 */
/*
diff --git a/src/mesa/x86-64/glapi_x86-64.S b/src/mesa/x86-64/glapi_x86-64.S
index 4c9eab882b..bd5a657e19 100644
--- a/src/mesa/x86-64/glapi_x86-64.S
+++ b/src/mesa/x86-64/glapi_x86-64.S
@@ -45,7 +45,7 @@
# define GL_PREFIX(n) GLNAME(CONCAT(gl,n))
# endif
-#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
+#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
# define THREADS
#endif
diff --git a/src/mesa/x86/glapi_x86.S b/src/mesa/x86/glapi_x86.S
index 13270ef35d..ae5dd2b0d1 100644
--- a/src/mesa/x86/glapi_x86.S
+++ b/src/mesa/x86/glapi_x86.S
@@ -52,7 +52,7 @@
#define GLOBL_FN(x) GLOBL x
#endif
-#if defined(PTHREADS) || defined(SOLARIS_THREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
+#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
# define THREADS
#endif
--
cgit v1.2.3
From 8bd8aec81d0310a3b790d425c41968003b454380 Mon Sep 17 00:00:00 2001
From: George Sapountzis
Date: Wed, 3 Mar 2010 21:22:38 +0200
Subject: glapi: drop condvar
Seems unused and replaced by functionality in os module.
---
src/mesa/glapi/glthread.h | 46 +---------------------------------------------
1 file changed, 1 insertion(+), 45 deletions(-)
(limited to 'src/mesa/glapi/glthread.h')
diff --git a/src/mesa/glapi/glthread.h b/src/mesa/glapi/glthread.h
index e5193aaf98..4fe99284a8 100644
--- a/src/mesa/glapi/glthread.h
+++ b/src/mesa/glapi/glthread.h
@@ -107,48 +107,6 @@ 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 /* PTHREADS */
@@ -245,12 +203,10 @@ typedef benaphore _glthread_Mutex;
#endif /* BEOS_THREADS */
-
-#ifndef THREADS
-
/*
* THREADS not defined
*/
+#ifndef THREADS
typedef unsigned _glthread_TSD;
--
cgit v1.2.3