aboutsummaryrefslogtreecommitdiff
path: root/xorg-server/glx
diff options
context:
space:
mode:
Diffstat (limited to 'xorg-server/glx')
-rw-r--r--xorg-server/glx/glapi.c122
-rw-r--r--xorg-server/glx/glthread.c84
-rw-r--r--xorg-server/glx/glthread.h111
3 files changed, 74 insertions, 243 deletions
diff --git a/xorg-server/glx/glapi.c b/xorg-server/glx/glapi.c
index 09b7149dc..7c75d2d5a 100644
--- a/xorg-server/glx/glapi.c
+++ b/xorg-server/glx/glapi.c
@@ -220,8 +220,6 @@ PUBLIC const void *_glapi_Context = NULL;
#if defined(THREADS)
-static GLboolean ThreadSafe = GL_FALSE; /**< In thread-safe mode? */
-
_glthread_TSD _gl_DispatchTSD; /**< Per-thread dispatch pointer */
static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
@@ -268,31 +266,11 @@ _glthread_DECLARE_STATIC_MUTEX(ThreadCheckMutex);
#define CHECK_MULTITHREAD_UNLOCK() _glthread_UNLOCK_MUTEX(ThreadCheckMutex)
#endif
/**
- * We should call this periodically from a function such as glXMakeCurrent
- * in order to test if multiple threads are being used.
+ * xserver's gl is not multithreaded, we promise.
*/
PUBLIC void
_glapi_check_multithread(void)
{
- static unsigned long knownID;
- static GLboolean firstCall = GL_TRUE;
-
- if (ThreadSafe)
- return;
-
- CHECK_MULTITHREAD_LOCK();
- if (firstCall) {
- _glapi_init_multithread();
-
- knownID = _glthread_GetID();
- firstCall = GL_FALSE;
- }
- else if (knownID != _glthread_GetID()) {
- ThreadSafe = GL_TRUE;
- _glapi_set_dispatch(NULL);
- _glapi_set_context(NULL);
- }
- CHECK_MULTITHREAD_UNLOCK();
}
#else
@@ -321,7 +299,7 @@ _glapi_set_context(void *context)
_glapi_tls_Context = context;
#elif defined(THREADS)
_glthread_SetTSD(&ContextTSD, context);
- _glapi_Context = (ThreadSafe) ? NULL : context;
+ _glapi_Context = context;
#else
_glapi_Context = context;
#endif
@@ -339,8 +317,6 @@ _glapi_get_context(void)
{
#if defined(GLX_USE_TLS)
return _glapi_tls_Context;
-#elif defined(THREADS)
- return (ThreadSafe) ? _glthread_GetTSD(&ContextTSD) : _glapi_Context;
#else
return _glapi_Context;
#endif
@@ -362,18 +338,9 @@ _glapi_set_dispatch(struct _glapi_table *dispatch)
/* use the no-op functions */
dispatch = (struct _glapi_table *) __glapi_noop_table;
}
-#ifdef DEBUG
- else {
- _glapi_check_table_not_null(dispatch);
- _glapi_check_table(dispatch);
- }
-#endif
#if defined(GLX_USE_TLS)
_glapi_tls_Dispatch = dispatch;
-#elif defined(THREADS)
- _glthread_SetTSD(&_gl_DispatchTSD, (void *) dispatch);
- _glapi_Dispatch = (ThreadSafe) ? NULL : dispatch;
#else
_glapi_Dispatch = dispatch;
#endif
@@ -389,10 +356,6 @@ _glapi_get_dispatch(void)
{
#if defined(GLX_USE_TLS)
return _glapi_tls_Dispatch;
-#elif defined(THREADS)
- return (ThreadSafe)
- ? (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD)
- : _glapi_Dispatch;
#else
return _glapi_Dispatch;
#endif
@@ -1128,84 +1091,3 @@ _glapi_get_dispatch_table_size(void)
return FIRST_DYNAMIC_OFFSET + MAX_EXTENSION_FUNCS;
}
-
-/**
- * Make sure there are no NULL pointers in the given dispatch table.
- * Intended for debugging purposes.
- */
-void
-_glapi_check_table_not_null(const struct _glapi_table *table)
-{
-#ifdef EXTRA_DEBUG /* set to DEBUG for extra DEBUG */
- const GLuint entries = _glapi_get_dispatch_table_size();
- const void **tab = (const void **) table;
- GLuint i;
- for (i = 1; i < entries; i++) {
- assert(tab[i]);
- }
-#else
- (void) table;
-#endif
-}
-
-
-/**
- * Do some spot checks to be sure that the dispatch table
- * slots are assigned correctly. For debugging only.
- */
-void
-_glapi_check_table(const struct _glapi_table *table)
-{
-#ifdef EXTRA_DEBUG /* set to DEBUG for extra DEBUG */
- {
- GLuint BeginOffset = _glapi_get_proc_offset("glBegin");
- char *BeginFunc = (char*) &table->Begin;
- GLuint offset = (BeginFunc - (char *) table) / sizeof(void *);
- assert(BeginOffset == offset);
- }
- {
- GLuint viewportOffset = _glapi_get_proc_offset("glViewport");
- char *viewportFunc = (char*) &table->Viewport;
- GLuint offset = (viewportFunc - (char *) table) / sizeof(void *);
- assert(viewportOffset == offset);
- }
- {
- GLuint VertexPointerOffset = _glapi_get_proc_offset("glVertexPointer");
- char *VertexPointerFunc = (char*) &table->VertexPointer;
- GLuint offset = (VertexPointerFunc - (char *) table) / sizeof(void *);
- assert(VertexPointerOffset == offset);
- }
- {
- GLuint ResetMinMaxOffset = _glapi_get_proc_offset("glResetMinmax");
- char *ResetMinMaxFunc = (char*) &table->ResetMinmax;
- GLuint offset = (ResetMinMaxFunc - (char *) table) / sizeof(void *);
- assert(ResetMinMaxOffset == offset);
- }
- {
- GLuint blendColorOffset = _glapi_get_proc_offset("glBlendColor");
- char *blendColorFunc = (char*) &table->BlendColor;
- GLuint offset = (blendColorFunc - (char *) table) / sizeof(void *);
- assert(blendColorOffset == offset);
- }
- {
- GLuint secondaryColor3fOffset = _glapi_get_proc_offset("glSecondaryColor3fEXT");
- char *secondaryColor3fFunc = (char*) &table->SecondaryColor3fEXT;
- GLuint offset = (secondaryColor3fFunc - (char *) table) / sizeof(void *);
- assert(secondaryColor3fOffset == offset);
- }
- {
- GLuint pointParameterivOffset = _glapi_get_proc_offset("glPointParameterivNV");
- char *pointParameterivFunc = (char*) &table->PointParameterivNV;
- GLuint offset = (pointParameterivFunc - (char *) table) / sizeof(void *);
- assert(pointParameterivOffset == offset);
- }
- {
- GLuint setFenceOffset = _glapi_get_proc_offset("glSetFenceNV");
- char *setFenceFunc = (char*) &table->SetFenceNV;
- GLuint offset = (setFenceFunc - (char *) table) / sizeof(void *);
- assert(setFenceOffset == offset);
- }
-#else
- (void) table;
-#endif
-}
diff --git a/xorg-server/glx/glthread.c b/xorg-server/glx/glthread.c
index c466e9bf0..5da7e433c 100644
--- a/xorg-server/glx/glthread.c
+++ b/xorg-server/glx/glthread.c
@@ -25,15 +25,13 @@
/*
* XXX There's probably some work to do in order to make this file
- * truly reusable outside of Mesa. First, the glheader.h include must go.
+ * truly reusable outside of Mesa.
*/
+
#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#include <X11/Xfuncproto.h>
-#ifndef PUBLIC
-#define PUBLIC
-#endif
#endif
#include <stdlib.h>
@@ -74,7 +72,7 @@
*/
#ifdef PTHREADS
-PUBLIC unsigned long
+_X_EXPORT unsigned long
_glthread_GetID(void)
{
return (unsigned long) pthread_self();
@@ -116,8 +114,6 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
#endif /* PTHREADS */
-
-
/*
* Win32 Threads. The only available option for Windows 95/NT.
* Be sure that you compile using the Multithreaded runtime, otherwise
@@ -125,12 +121,20 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
*/
#ifdef WIN32_THREADS
-static void InsteadOf_exit(int nCode)
+void FreeTSD(_glthread_TSD *p)
{
- DWORD dwErr = GetLastError();
+ if (p->initMagic==INIT_MAGIC) {
+ TlsFree(p->key);
+ p->initMagic=0;
+ }
}
-PUBLIC unsigned long
+void InsteadOf_exit(int nCode)
+{
+ DWORD dwErr=GetLastError();
+}
+
+unsigned long
_glthread_GetID(void)
{
return GetCurrentThreadId();
@@ -142,24 +146,13 @@ _glthread_InitTSD(_glthread_TSD *tsd)
{
tsd->key = TlsAlloc();
if (tsd->key == TLS_OUT_OF_INDEXES) {
- perror(INIT_TSD_ERROR);
+ perror("Mesa:_glthread_InitTSD");
InsteadOf_exit(-1);
}
tsd->initMagic = INIT_MAGIC;
}
-void
-_glthread_DestroyTSD(_glthread_TSD *tsd)
-{
- if (tsd->initMagic != INIT_MAGIC) {
- return;
- }
- TlsFree(tsd->key);
- tsd->initMagic = 0x0;
-}
-
-
void *
_glthread_GetTSD(_glthread_TSD *tsd)
{
@@ -179,61 +172,20 @@ _glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
_glthread_InitTSD(tsd);
}
if (TlsSetValue(tsd->key, ptr) == 0) {
- perror(SET_TSD_ERROR);
- InsteadOf_exit(-1);
+ perror("Mesa:_glthread_SetTSD");
+ InsteadOf_exit(-1);
}
}
#endif /* WIN32_THREADS */
-/*
- * BeOS threads
- */
-#ifdef BEOS_THREADS
-
-PUBLIC unsigned long
-_glthread_GetID(void)
-{
- return (unsigned long) find_thread(NULL);
-}
-
-void
-_glthread_InitTSD(_glthread_TSD *tsd)
-{
- tsd->key = tls_allocate();
- tsd->initMagic = INIT_MAGIC;
-}
-
-void *
-_glthread_GetTSD(_glthread_TSD *tsd)
-{
- if (tsd->initMagic != (int) INIT_MAGIC) {
- _glthread_InitTSD(tsd);
- }
- return tls_get(tsd->key);
-}
-
-void
-_glthread_SetTSD(_glthread_TSD *tsd, void *ptr)
-{
- if (tsd->initMagic != (int) INIT_MAGIC) {
- _glthread_InitTSD(tsd);
- }
- tls_set(tsd->key, ptr);
-}
-
-#endif /* BEOS_THREADS */
-
-
-
#else /* THREADS */
-
/*
* no-op functions
*/
-PUBLIC unsigned long
+_X_EXPORT unsigned long
_glthread_GetID(void)
{
return 0;
diff --git a/xorg-server/glx/glthread.h b/xorg-server/glx/glthread.h
index 4fe99284a..28793fcc7 100644
--- a/xorg-server/glx/glthread.h
+++ b/xorg-server/glx/glthread.h
@@ -64,12 +64,18 @@
#define GLTHREAD_H
-#if defined(PTHREADS) || defined(WIN32_THREADS) || defined(BEOS_THREADS)
-#ifndef THREADS
-#define THREADS
+#if defined(USE_MGL_NAMESPACE)
+#define _glapi_Dispatch _mglapi_Dispatch
#endif
+
+#if (defined(PTHREADS) || defined(WIN32_THREADS)) \
+ && !defined(THREADS)
+# define THREADS
#endif
+#ifdef VMS
+#include <GL/vms_x_fix.h>
+#endif
/*
* POSIX threads. This should be your choice in the Unix world
@@ -110,6 +116,18 @@ typedef pthread_mutex_t _glthread_Mutex;
#endif /* PTHREADS */
+
+
+/*
+ * 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.
+ */
+
+
+
+
/*
* Windows threads. Should work with Windows NT and 95.
* IMPORTANT: Link with multithreaded runtime library when THREADS are
@@ -127,44 +145,22 @@ 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 */
-
/*
* BeOS threads. R5.x required.
*/
#ifdef BEOS_THREADS
-/* Problem with OS.h and this file on haiku */
-#ifndef __HAIKU__
#include <kernel/OS.h>
-#endif
-
#include <support/TLS.h>
-/* The only two typedefs required here
- * this is cause of the OS.h problem
- */
-#ifdef __HAIKU__
-typedef int32 thread_id;
-typedef int32 sem_id;
-#endif
-
typedef struct {
int32 key;
int initMagic;
@@ -179,40 +175,28 @@ typedef struct {
} benaphore;
typedef benaphore _glthread_Mutex;
-#define _glthread_DECLARE_STATIC_MUTEX(name) \
- static _glthread_Mutex name = { 0, 0 }
+#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_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)
+#endif /* BEOS_THREADS */
-#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;
+typedef int _glthread_TSD;
-typedef unsigned _glthread_Thread;
+typedef int _glthread_Thread;
-typedef unsigned _glthread_Mutex;
+typedef int _glthread_Mutex;
#define _glthread_DECLARE_STATIC_MUTEX(name) static _glthread_Mutex name = 0
@@ -240,10 +224,6 @@ extern void
_glthread_InitTSD(_glthread_TSD *);
-extern void
-_glthread_DestroyTSD(_glthread_TSD *); /* WIN32 only */
-
-
extern void *
_glthread_GetTSD(_glthread_TSD *);
@@ -251,5 +231,22 @@ _glthread_GetTSD(_glthread_TSD *);
extern void
_glthread_SetTSD(_glthread_TSD *, void *);
+#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 */