summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mesa/glapi/glapi.c70
-rw-r--r--src/mesa/glapi/glapi.h15
2 files changed, 76 insertions, 9 deletions
diff --git a/src/mesa/glapi/glapi.c b/src/mesa/glapi/glapi.c
index 47dd1dfe44..ed1a0c97da 100644
--- a/src/mesa/glapi/glapi.c
+++ b/src/mesa/glapi/glapi.c
@@ -1,4 +1,4 @@
-/* $Id: glapi.c,v 1.17 1999/12/17 12:20:23 brianp Exp $ */
+/* $Id: glapi.c,v 1.18 1999/12/17 14:51:28 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -49,11 +49,14 @@
/* Flag to indicate whether thread-safe dispatch is enabled */
-static GLboolean ThreadSafe = GL_FALSE;
+GLboolean _glapi_ThreadSafe = GL_FALSE;
/* This is used when thread safety is disabled */
static struct _glapi_table *Dispatch = &__glapi_noop_table;
+/* Used when thread safety disabled */
+void *_glapi_CurrentContext = NULL;
+
#if defined(THREADS)
@@ -66,6 +69,14 @@ static void dispatch_thread_init()
_glthread_InitTSD(&DispatchTSD);
}
+
+static _glthread_TSD ContextTSD;
+
+static void context_thread_init()
+{
+ _glthread_InitTSD(&ContextTSD);
+}
+
#endif
@@ -84,7 +95,7 @@ void
_glapi_check_multithread(void)
{
#if defined(THREADS)
- if (!ThreadSafe) {
+ if (!_glapi_ThreadSafe) {
static unsigned long knownID;
static GLboolean firstCall = GL_TRUE;
if (firstCall) {
@@ -92,10 +103,10 @@ _glapi_check_multithread(void)
firstCall = GL_FALSE;
}
else if (knownID != _glthread_GetID()) {
- ThreadSafe = GL_TRUE;
+ _glapi_ThreadSafe = GL_TRUE;
}
}
- if (ThreadSafe) {
+ if (_glapi_ThreadSafe) {
/* make sure that this thread's dispatch pointer isn't null */
if (!_glapi_get_dispatch()) {
_glapi_set_dispatch(NULL);
@@ -107,6 +118,49 @@ _glapi_check_multithread(void)
/*
+ * Set the current context pointer for this thread.
+ * The context pointer is an opaque type which should be cast to
+ * void from the real context pointer type.
+ */
+void
+_glapi_set_current_context(void *context)
+{
+#if defined(THREADS)
+ _glthread_SetTSD(&ContextTSD, context, context_thread_init);
+ if (_glapi_ThreadSafe)
+ _glapi_CurrentContext = NULL; /* to help with debugging */
+ else
+ _glapi_CurrentContext = context;
+#else
+ _glapi_CurrentContext = context;
+#endif
+}
+
+
+
+/*
+ * Get the current context pointer for this thread.
+ * The context pointer is an opaque type which should be cast from
+ * void to the real context pointer type.
+ */
+void *
+_glapi_get_current_context(void)
+{
+#if defined(THREADS)
+ if (_glapi_ThreadSafe) {
+ return _glthread_GetTSD(&ContextTSD);
+ }
+ else {
+ return _glapi_CurrentContext;
+ }
+#else
+ return _glapi_CurrentContext;
+#endif
+}
+
+
+
+/*
* Set the global or per-thread dispatch table pointer.
*/
void
@@ -124,7 +178,7 @@ _glapi_set_dispatch(struct _glapi_table *dispatch)
#if defined(THREADS)
_glthread_SetTSD(&DispatchTSD, (void*) dispatch, dispatch_thread_init);
- if (ThreadSafe)
+ if (_glapi_ThreadSafe)
Dispatch = NULL; /* to help with debugging */
else
Dispatch = dispatch;
@@ -142,7 +196,7 @@ struct _glapi_table *
_glapi_get_dispatch(void)
{
#if defined(THREADS)
- if (ThreadSafe) {
+ if (_glapi_ThreadSafe) {
return (struct _glapi_table *) _glthread_GetTSD(&DispatchTSD);
}
else {
@@ -453,7 +507,7 @@ _glapi_check_table(const struct _glapi_table *table)
#define DISPATCH_SETUP \
const struct _glapi_table *dispatch; \
- if (ThreadSafe) { \
+ if (_glapi_ThreadSafe) { \
dispatch = _glapi_get_dispatch(); \
} \
else { \
diff --git a/src/mesa/glapi/glapi.h b/src/mesa/glapi/glapi.h
index 9f12b2c08e..5486819da5 100644
--- a/src/mesa/glapi/glapi.h
+++ b/src/mesa/glapi/glapi.h
@@ -1,4 +1,4 @@
-/* $Id: glapi.h,v 1.10 1999/12/16 17:33:44 brianp Exp $ */
+/* $Id: glapi.h,v 1.11 1999/12/17 14:51:29 brianp Exp $ */
/*
* Mesa 3-D graphics library
@@ -34,11 +34,24 @@
struct _glapi_table;
+extern GLboolean _glapi_ThreadSafe;
+
+extern void *_glapi_CurrentContext;
+
+
extern void
_glapi_check_multithread(void);
extern void
+_glapi_set_current_context(void *context);
+
+
+extern void *
+_glapi_get_current_context(void);
+
+
+extern void
_glapi_set_dispatch(struct _glapi_table *dispatch);