thread support now works

This commit is contained in:
Brian Paul
1999-12-16 17:31:59 +00:00
parent c11371a4e5
commit bb72d326a0
2 changed files with 88 additions and 38 deletions

View File

@@ -1,4 +1,4 @@
/* $Id: glapi.c,v 1.14 1999/12/16 12:38:11 brianp Exp $ */ /* $Id: glapi.c,v 1.15 1999/12/16 17:31:59 brianp Exp $ */
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
@@ -44,39 +44,78 @@
#include "glapioffsets.h" #include "glapioffsets.h"
#include "glapitable.h" #include "glapitable.h"
#include <stdio.h>
/* Flag to indicate whether thread-safe dispatch is enabled */ /* Flag to indicate whether thread-safe dispatch is enabled */
static GLboolean ThreadSafe = GL_TRUE; static GLboolean ThreadSafe = GL_FALSE;
/* This is used when thread safety is disabled */ /* This is used when thread safety is disabled */
static struct _glapi_table *Dispatch = &__glapi_noop_table; static struct _glapi_table *Dispatch = &__glapi_noop_table;
#if defined(THREADS) #if defined(THREADS)
#include "mthreads.h"
static MesaTSD mesa_dispatch_tsd; #include "glthread.h"
static void mesa_dispatch_thread_init() {
MesaInitTSD(&mesa_dispatch_tsd); static _glthread_TSD DispatchTSD;
static void dispatch_thread_init()
{
_glthread_InitTSD(&DispatchTSD);
} }
#endif #endif
#define DISPATCH_SETUP \ static GLuint MaxDispatchOffset = sizeof(struct _glapi_table) / sizeof(void *) - 1;
const struct _glapi_table *dispatch; \ static GLboolean GetSizeCalled = GL_FALSE;
if (ThreadSafe) { \
dispatch = _glapi_get_dispatch(); \
} \
else { \ /*
dispatch = Dispatch; \ * We should call this periodically from a function such as glXMakeCurrent
* in order to test if multiple threads are being used. When we detect
* that situation we should then call _glapi_enable_thread_safety()
*/
void
_glapi_check_multithread(void)
{
#if defined(THREADS)
if (!ThreadSafe) {
static unsigned long knownID;
static GLboolean firstCall = GL_TRUE;
if (firstCall) {
knownID = _glthread_GetID();
firstCall = GL_FALSE;
}
else if (knownID != _glthread_GetID()) {
ThreadSafe = GL_TRUE;
}
}
if (ThreadSafe) {
/* make sure that this thread's dispatch pointer isn't null */
if (!_glapi_get_dispatch()) {
_glapi_set_dispatch(NULL);
}
}
#endif
} }
#define DISPATCH(FUNC, ARGS) (dispatch->FUNC) ARGS
static GLuint MaxDispatchOffset = sizeof(struct _glapi_table) / sizeof(void *); /*
static GLboolean GetSizeCalled = GL_FALSE; * Enable thread safe mode. Once enabled, can't be disabled.
*/
void
_glapi_enable_thread_safety(void)
{
ThreadSafe = GL_TRUE;
}
/* /*
@@ -96,22 +135,26 @@ _glapi_set_dispatch(struct _glapi_table *dispatch)
#endif #endif
#if defined(THREADS) #if defined(THREADS)
MesaSetTSD(&mesa_dispatch_tsd, (void*) dispatch, mesa_dispatch_thread_init); _glthread_SetTSD(&DispatchTSD, (void*) dispatch, dispatch_thread_init);
#else #else
Dispatch = dispatch; Dispatch = dispatch;
#endif #endif
} }
/* /*
* Get the global or per-thread dispatch table pointer. * Return pointer to current dispatch table for calling thread.
*/ */
struct _glapi_table * struct _glapi_table *
_glapi_get_dispatch(void) _glapi_get_dispatch(void)
{ {
#if defined(THREADS) #if defined(THREADS)
/* return this thread's dispatch pointer */ if (ThreadSafe) {
return (struct _glapi_table *) MesaGetTSD(&mesa_dispatch_tsd); return (struct _glapi_table *) _glthread_GetTSD(&DispatchTSD);
}
else
return Dispatch;
#else #else
return Dispatch; return Dispatch;
#endif #endif
@@ -119,14 +162,6 @@ _glapi_get_dispatch(void)
void
_glapi_enable_thread_safety(void)
{
ThreadSafe = GL_TRUE;
}
/* /*
* Return size of dispatch table struct as number of functions (or * Return size of dispatch table struct as number of functions (or
* slots). * slots).
@@ -196,7 +231,7 @@ get_static_proc_address(const char *funcName)
/********************************************************************** /**********************************************************************
* Extension function management. * Extension function management.
**********************************************************************/ */
struct _glapi_ext_entrypoint { struct _glapi_ext_entrypoint {
@@ -410,7 +445,7 @@ _glapi_check_table(const struct _glapi_table *table)
/* /**********************************************************************
* Generate the GL entrypoint functions here. * Generate the GL entrypoint functions here.
*/ */
@@ -422,6 +457,21 @@ _glapi_check_table(const struct _glapi_table *table)
#define NAME(func) gl##func #define NAME(func) gl##func
#endif #endif
#define DISPATCH_SETUP \
const struct _glapi_table *dispatch; \
if (ThreadSafe) { \
dispatch = _glapi_get_dispatch(); \
assert(dispatch); \
} \
else { \
dispatch = Dispatch; \
}
#define DISPATCH(FUNC, ARGS) (dispatch->FUNC) ARGS
#include "glapitemp.h" #include "glapitemp.h"

View File

@@ -1,4 +1,4 @@
/* $Id: glapi.h,v 1.8 1999/12/16 12:38:54 brianp Exp $ */ /* $Id: glapi.h,v 1.9 1999/12/16 17:31:59 brianp Exp $ */
/* /*
* Mesa 3-D graphics library * Mesa 3-D graphics library
@@ -35,6 +35,10 @@
struct _glapi_table; struct _glapi_table;
extern void
_glapi_check_multithread(void);
extern void extern void
_glapi_set_dispatch(struct _glapi_table *dispatch); _glapi_set_dispatch(struct _glapi_table *dispatch);
@@ -43,10 +47,6 @@ extern struct _glapi_table *
_glapi_get_dispatch(void); _glapi_get_dispatch(void);
extern void
_glapi_enable_thread_safety(void);
extern GLuint extern GLuint
_glapi_get_dispatch_table_size(void); _glapi_get_dispatch_table_size(void);