[Piglit] [PATCH 1/2] glx: Replace extra mutexes with XInitThreads

Paul Berry stereotype441 at gmail.com
Mon Nov 19 10:57:34 PST 2012


From: Ian Romanick <ian.d.romanick at intel.com>

To use multithreading with xlib, you're supposed to call XInitThreads
before any other xlib call.  Without this, xlib and GLX calls won't be
thread safe.  It looks like this test had an extra mutex to work
around the lack of thread saftey in glXCreateContext and
glXMakeCurrent.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 tests/glx/glx-multithread.c | 9 +--------
 1 file changed, 1 insertion(+), 8 deletions(-)

diff --git a/tests/glx/glx-multithread.c b/tests/glx/glx-multithread.c
index 10095f3..c5b4f98 100644
--- a/tests/glx/glx-multithread.c
+++ b/tests/glx/glx-multithread.c
@@ -38,7 +38,6 @@
 int piglit_width = 50, piglit_height = 50;
 static Display *dpy;
 static Window win;
-static pthread_mutex_t mutex;
 static XVisualInfo *visinfo;
 
 static void *
@@ -48,8 +47,6 @@ thread_func(void *arg)
 	int *x = arg;
 	Bool ret;
 
-	pthread_mutex_lock(&mutex);
-
 	ctx = piglit_get_glx_context(dpy, visinfo);
 	ret = glXMakeCurrent(dpy, win, ctx);
 	assert(ret);
@@ -61,8 +58,6 @@ thread_func(void *arg)
 	glFlush();
 	glXDestroyContext(dpy, ctx);
 
-	pthread_mutex_unlock(&mutex);
-
 	return NULL;
 }
 
@@ -86,7 +81,6 @@ draw(Display *dpy)
 	glClear(GL_COLOR_BUFFER_BIT);
 	glFlush();
 
-	pthread_mutex_init(&mutex, NULL);
 	/* Now, spawn some threads that do some drawing, both with this
 	 * context
 	 */
@@ -98,8 +92,6 @@ draw(Display *dpy)
 	ret = pthread_join(thread2, &retval);
 	assert(ret == 0);
 
-	pthread_mutex_destroy(&mutex);
-
 	pass &= piglit_probe_pixel_rgb(15, 15, green);
 	pass &= piglit_probe_pixel_rgb(35, 15, green);
 
@@ -120,6 +112,7 @@ main(int argc, char **argv)
 			fprintf(stderr, "Unknown option: %s\n", argv[i]);
 	}
 
+	XInitThreads();
 	dpy = XOpenDisplay(NULL);
 	if (dpy == NULL) {
 		fprintf(stderr, "couldn't open display\n");
-- 
1.8.0



More information about the Piglit mailing list