summaryrefslogtreecommitdiff
path: root/src/mesa/glapi/glapi.c
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>1999-12-15 15:02:30 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>1999-12-15 15:02:30 +0000
commit0f710258c22ca1ee4a009162c4c63562a061306a (patch)
tree319af2ab1a96e8653edd7a98e614669003ccbd20 /src/mesa/glapi/glapi.c
parent77e898629ecaecf257ee7f2d5c91469904aabb27 (diff)
new thread code
Diffstat (limited to 'src/mesa/glapi/glapi.c')
-rw-r--r--src/mesa/glapi/glapi.c69
1 files changed, 50 insertions, 19 deletions
diff --git a/src/mesa/glapi/glapi.c b/src/mesa/glapi/glapi.c
index 1a6b424e01..944e77ac53 100644
--- a/src/mesa/glapi/glapi.c
+++ b/src/mesa/glapi/glapi.c
@@ -1,4 +1,4 @@
-/* $Id: glapi.c,v 1.12 1999/12/15 12:52:31 brianp Exp $ */
+/* $Id: glapi.c,v 1.13 1999/12/15 15:02:30 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -43,32 +43,37 @@
#include "glapinoop.h"
+/* Flag to indicate whether thread-safe dispatch is enabled */
+static GLboolean ThreadSafe = GL_FALSE;
-/*
- * Define the DISPATCH_SETUP and DISPATCH macros here dependant on
- * whether or not threading is enabled.
- */
-#if defined(THREADS)
+/* This is used when thread safety is disabled */
+static struct _glapi_table *Dispatch = &__glapi_noop_table;
-/*** Thread-safe API dispatch ***/
+
+#if defined(THREADS)
#include "mthreads.h"
static MesaTSD mesa_dispatch_tsd;
static void mesa_dispatch_thread_init() {
MesaInitTSD(&mesa_dispatch_tsd);
}
-#define DISPATCH_SETUP struct _glapi_table *dispatch = (struct _glapi_table *) MesaGetTSD(&mesa_dispatch_tsd)
-#define DISPATCH(FUNC, ARGS) (dispatch->FUNC) ARGS
+#endif
-#else
-/*** Non-threaded API dispatch ***/
-static struct _glapi_table *Dispatch = &__glapi_noop_table;
-#define DISPATCH_SETUP
-#define DISPATCH(FUNC, ARGS) (Dispatch->FUNC) ARGS
+#define DISPATCH_SETUP \
+ const struct _glapi_table *dispatch; \
+ if (ThreadSafe) { \
+ dispatch = _glapi_get_dispatch(); \
+ } \
+ else { \
+ dispatch = Dispatch; \
+ }
+
+#define DISPATCH(FUNC, ARGS) (dispatch->FUNC) ARGS
-#endif
+static GLuint MaxDispatchOffset = sizeof(struct _glapi_table) / sizeof(void *);
+static GLboolean GetSizeCalled = GL_FALSE;
/*
@@ -111,6 +116,14 @@ _glapi_get_dispatch(void)
+void
+_glapi_enable_thread_safety(void)
+{
+ ThreadSafe = GL_TRUE;
+}
+
+
+
/*
* Return size of dispatch table struct as number of functions (or
* slots).
@@ -118,7 +131,9 @@ _glapi_get_dispatch(void)
GLuint
_glapi_get_dispatch_table_size(void)
{
- return sizeof(struct _glapi_table) / sizeof(void *);
+ /* return sizeof(struct _glapi_table) / sizeof(void *);*/
+ GetSizeCalled = GL_TRUE;
+ return MaxDispatchOffset + 1;
}
@@ -678,13 +693,23 @@ generate_entrypoint(GLuint offset)
GLboolean
_glapi_add_entrypoint(const char *funcName, GLuint offset)
{
+ GLint index;
+
+ /* Make sure we don't try to add a new entrypoint after someone
+ * has already called _glapi_get_dispatch_table_size()! If that's
+ * happened the caller's information will now be out of date.
+ */
+ assert(!GetSizeCalled);
+
/* first check if the named function is already statically present */
- GLint index = get_static_proc_offset(funcName);
+ index = get_static_proc_offset(funcName);
+
if (index >= 0) {
assert(index == offset);
return GL_TRUE;
}
- else if (offset < _glapi_get_dispatch_table_size()) {
+ /* else if (offset < _glapi_get_dispatch_table_size()) { */
+ else {
/* be sure index and name match known data */
GLuint i;
for (i = 0; i < NumExtEntryPoints; i++) {
@@ -703,11 +728,17 @@ _glapi_add_entrypoint(const char *funcName, GLuint offset)
ExtEntryTable[NumExtEntryPoints].Offset = offset;
ExtEntryTable[NumExtEntryPoints].Address = generate_entrypoint(offset);
NumExtEntryPoints++;
+
+ if (offset > MaxDispatchOffset)
+ MaxDispatchOffset = offset;
+
return GL_TRUE;
}
+/*
else {
return GL_FALSE;
}
+*/
}
@@ -759,7 +790,7 @@ _glapi_get_proc_address(const char *funcName)
void
_glapi_check_table(const struct _glapi_table *table)
{
- const GLuint entries = sizeof(struct _glapi_table) / sizeof(void *);
+ const GLuint entries = _glapi_get_dispatch_table_size();
const void **tab = (const void **) table;
GLuint i;
for (i = 0; i < entries; i++) {