-/* $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
/* 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)
_glthread_InitTSD(&DispatchTSD);
}
+
+static _glthread_TSD ContextTSD;
+
+static void context_thread_init()
+{
+ _glthread_InitTSD(&ContextTSD);
+}
+
#endif
_glapi_check_multithread(void)
{
#if defined(THREADS)
- if (!ThreadSafe) {
+ if (!_glapi_ThreadSafe) {
static unsigned long knownID;
static GLboolean firstCall = GL_TRUE;
if (firstCall) {
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);
+/*
+ * 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.
*/
#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;
_glapi_get_dispatch(void)
{
#if defined(THREADS)
- if (ThreadSafe) {
+ if (_glapi_ThreadSafe) {
return (struct _glapi_table *) _glthread_GetTSD(&DispatchTSD);
}
else {
#define DISPATCH_SETUP \
const struct _glapi_table *dispatch; \
- if (ThreadSafe) { \
+ if (_glapi_ThreadSafe) { \
dispatch = _glapi_get_dispatch(); \
} \
else { \
-/* $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
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);