From 5e3276f5c7bf1a363de710709737624634389858 Mon Sep 17 00:00:00 2001
From: Emil Velikov
Date: Fri, 6 Mar 2015 17:07:11 +0000
Subject: [PATCH] Revert "glx: remove support for non-multithreaded platforms"
This reverts commit 38591295cd4b68f89f257b20f476f98de3772a47.
Not meant to go in yet. Lacking review.
---
docs/dispatch.html | 7 +++++--
src/glx/glxclient.h | 18 +++++++++++++++++-
src/glx/glxcurrent.c | 11 +++++++++++
src/glx/tests/fake_glx_screen.cpp | 2 +-
4 files changed, 34 insertions(+), 4 deletions(-)
diff --git a/docs/dispatch.html b/docs/dispatch.html
index 77cfba3221f..aacd01e0c65 100644
--- a/docs/dispatch.html
+++ b/docs/dispatch.html
@@ -185,6 +185,8 @@ ways that the dispatch table pointer can be accessed. There are four
different methods that can be used:
+- Using _glapi_Dispatch directly in builds for non-multithreaded
+environments.
- Using _glapi_Dispatch and _glapi_get_dispatch in
multithreaded environments.
- Using _glapi_Dispatch and pthread_getspecific in
@@ -202,8 +204,9 @@ terribly relevant.
few preprocessor defines.
-- If GLX_USE_TLS is defined, method #3 is used.
-- If HAVE_PTHREAD is defined, method #2 is used.
+- If GLX_USE_TLS is defined, method #4 is used.
+- If HAVE_PTHREAD is defined, method #3 is used.
+- If WIN32_THREADS is defined, method #2 is used.
- If none of the preceding are defined, method #1 is used.
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index 30c9e521395..122ae5dd1b7 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -47,11 +47,13 @@
#include
#include
#include
-#include
#include
#include "GL/glxproto.h"
#include "glxconfig.h"
#include "glxhash.h"
+#if defined( HAVE_PTHREAD )
+# include
+#endif
#include "util/macros.h"
#include "glxextensions.h"
@@ -627,6 +629,7 @@ extern void __glXPreferEGL(int state);
extern int __glXDebug;
/* This is per-thread storage in an MT environment */
+#if defined( HAVE_PTHREAD )
extern void __glXSetCurrentContext(struct glx_context * c);
@@ -643,6 +646,14 @@ extern struct glx_context *__glXGetCurrentContext(void);
# endif /* defined( GLX_USE_TLS ) */
+#else
+
+extern struct glx_context *__glXcurrentContext;
+#define __glXGetCurrentContext() __glXcurrentContext
+#define __glXSetCurrentContext(gc) __glXcurrentContext = gc
+
+#endif /* defined( HAVE_PTHREAD ) */
+
extern void __glXSetCurrentContextNull(void);
@@ -650,9 +661,14 @@ extern void __glXSetCurrentContextNull(void);
** Global lock for all threads in this address space using the GLX
** extension
*/
+#if defined( HAVE_PTHREAD )
extern pthread_mutex_t __glXmutex;
#define __glXLock() pthread_mutex_lock(&__glXmutex)
#define __glXUnlock() pthread_mutex_unlock(&__glXmutex)
+#else
+#define __glXLock()
+#define __glXUnlock()
+#endif
/*
** Setup for a command. Initialize the extension for dpy if necessary.
diff --git a/src/glx/glxcurrent.c b/src/glx/glxcurrent.c
index 7f47a427771..86fb658ca5e 100644
--- a/src/glx/glxcurrent.c
+++ b/src/glx/glxcurrent.c
@@ -33,7 +33,9 @@
* Client-side GLX interface for current context management.
*/
+#ifdef HAVE_PTHREAD
#include
+#endif
#include "glxclient.h"
@@ -65,6 +67,8 @@ struct glx_context dummyContext = {
* Current context management and locking
*/
+#if defined( HAVE_PTHREAD )
+
_X_HIDDEN pthread_mutex_t __glXmutex = PTHREAD_MUTEX_INITIALIZER;
# if defined( GLX_USE_TLS )
@@ -134,6 +138,13 @@ __glXGetCurrentContext(void)
# endif /* defined( GLX_USE_TLS ) */
+#else
+
+/* not thread safe */
+_X_HIDDEN struct glx_context *__glXcurrentContext = &dummyContext;
+
+#endif
+
_X_HIDDEN void
__glXSetCurrentContextNull(void)
diff --git a/src/glx/tests/fake_glx_screen.cpp b/src/glx/tests/fake_glx_screen.cpp
index db20749505c..ccb1afae47d 100644
--- a/src/glx/tests/fake_glx_screen.cpp
+++ b/src/glx/tests/fake_glx_screen.cpp
@@ -77,7 +77,7 @@ indirect_create_context_attribs(struct glx_screen *base,
__thread void *__glX_tls_Context = NULL;
-#if !defined(GLX_USE_TLS)
+#if defined(HAVE_PTHREAD) && !defined(GLX_USE_TLS)
extern "C" struct glx_context *
__glXGetCurrentContext()
{
--
2.30.2