summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Paul <brian.paul@tungstengraphics.com>2006-09-20 14:39:47 +0000
committerBrian Paul <brian.paul@tungstengraphics.com>2006-09-20 14:39:47 +0000
commitd41d29b8bde9bb9c277424a43d0b80838edfe254 (patch)
tree62b136996084e35b4a14392c5f06c4679df74fc6
parent0c54e47c0e93f725b8bc028b0d4614011dbe3fef (diff)
make current GLX context per-thread
-rw-r--r--src/mesa/drivers/x11/glxapi.c37
1 files changed, 33 insertions, 4 deletions
diff --git a/src/mesa/drivers/x11/glxapi.c b/src/mesa/drivers/x11/glxapi.c
index 4f3dca8f48..7945f1c5b0 100644
--- a/src/mesa/drivers/x11/glxapi.c
+++ b/src/mesa/drivers/x11/glxapi.c
@@ -124,9 +124,30 @@ get_dispatch(Display *dpy)
-/* Set by glXMakeCurrent() and glXMakeContextCurrent() only */
+/**
+ * GLX API current context.
+ */
+#if defined(GLX_USE_TLS)
+PUBLIC __thread void * CurrentContext
+ __attribute__((tls_model("initial-exec")));
+#elif defined(THREADS)
+static _glthread_TSD ContextTSD; /**< Per-thread context pointer */
+#else
static GLXContext CurrentContext = 0;
-#define __glXGetCurrentContext() CurrentContext;
+#endif
+
+
+static void
+SetCurrentContext(GLXContext c)
+{
+#if defined(GLX_USE_TLS)
+ CurrentContext = context;
+#elif defined(THREADS)
+ _glthread_SetTSD(&ContextTSD, c);
+#else
+ CurrentContext = c;
+#endif
+}
/*
@@ -186,6 +207,8 @@ glXDestroyContext(Display *dpy, GLXContext ctx)
GET_DISPATCH(dpy, t);
if (!t)
return;
+ if (glXGetCurrentContext() == ctx)
+ SetCurrentContext(NULL);
(t->DestroyContext)(dpy, ctx);
}
@@ -215,7 +238,13 @@ glXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value)
GLXContext PUBLIC
glXGetCurrentContext(void)
{
+#if defined(GLX_USE_TLS)
return CurrentContext;
+#elif defined(THREADS)
+ return _glthread_GetTSD(&ContextTSD);
+#else
+ return CurrentContext;
+#endif
}
@@ -249,7 +278,7 @@ glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx)
}
b = (*t->MakeCurrent)(dpy, drawable, ctx);
if (b) {
- CurrentContext = ctx;
+ SetCurrentContext(ctx);
}
return b;
}
@@ -524,7 +553,7 @@ glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXConte
return False;
b = (t->MakeContextCurrent)(dpy, draw, read, ctx);
if (b) {
- CurrentContext = ctx;
+ SetCurrentContext(ctx);
}
return b;
}