[PATCH 05/11] glx: Simplify _glapi_check_multithread

Adam Jackson ajax at redhat.com
Thu Mar 3 11:07:19 PST 2011


We can guarantee that the X server does not call DRI driver services
from multiple threads, so _glapi_check_multithread need never do
anything special.  As a result, ThreadSafe is always false, so remove it
and simplify expressions where it appeared to match.

Signed-off-by: Adam Jackson <ajax at redhat.com>
---
 glx/glapi.c |   49 ++++---------------------------------------------
 1 files changed, 4 insertions(+), 45 deletions(-)

diff --git a/glx/glapi.c b/glx/glapi.c
index 42bf6c1..fde5d76 100644
--- a/glx/glapi.c
+++ b/glx/glapi.c
@@ -175,12 +175,6 @@ static GLint NoOpUnused(void)
  * static dispatch functions access these variables via \c _glapi_get_dispatch
  * and \c _glapi_get_context.
  *
- * There is a race condition in setting \c _glapi_Dispatch to \c NULL.  It is
- * possible for the original thread to be setting it at the same instant a new
- * thread, perhaps running on a different processor, is clearing it.  Because
- * of that, \c ThreadSafe, which can only ever be changed to \c GL_TRUE, is
- * used to determine whether or not the application is multithreaded.
- * 
  * In the TLS case, the variables \c _glapi_Dispatch and \c _glapi_Context are
  * hardcoded to \c NULL.  Instead the TLS variables \c _glapi_tls_Dispatch and
  * \c _glapi_tls_Context are used.  Having \c _glapi_Dispatch and
@@ -204,7 +198,6 @@ PUBLIC const void *_glapi_Context = NULL;
 
 #if defined(THREADS)
 
-static GLboolean ThreadSafe = GL_FALSE;  /**< In thread-safe mode? */
 _glthread_TSD _gl_DispatchTSD;           /**< Per-thread dispatch pointer */
 static _glthread_TSD ContextTSD;         /**< Per-thread context pointer */
 
@@ -243,37 +236,14 @@ str_dup(const char *str)
 }
 
 
-
-/**
- * We should call this periodically from a function such as glXMakeCurrent
- * in order to test if multiple threads are being used.
+/*
+ * xserver's gl is not multithreaded, we promise.
  */
 PUBLIC void
 _glapi_check_multithread(void)
 {
-#if defined(THREADS) && !defined(GLX_USE_TLS)
-   if (!ThreadSafe) {
-      static unsigned long knownID;
-      static GLboolean firstCall = GL_TRUE;
-      if (firstCall) {
-         knownID = _glthread_GetID();
-         firstCall = GL_FALSE;
-      }
-      else if (knownID != _glthread_GetID()) {
-         ThreadSafe = GL_TRUE;
-         _glapi_set_dispatch(NULL);
-         _glapi_set_context(NULL);
-      }
-   }
-   else if (!_glapi_get_dispatch()) {
-      /* make sure that this thread's dispatch pointer isn't null */
-      _glapi_set_dispatch(NULL);
-   }
-#endif
 }
 
-
-
 /**
  * Set the current context pointer for this thread.
  * The context pointer is an opaque type which should be cast to
@@ -287,7 +257,7 @@ _glapi_set_context(void *context)
    _glapi_tls_Context = context;
 #elif defined(THREADS)
    _glthread_SetTSD(&ContextTSD, context);
-   _glapi_Context = (ThreadSafe) ? NULL : context;
+   _glapi_Context = context;
 #else
    _glapi_Context = context;
 #endif
@@ -305,13 +275,6 @@ _glapi_get_context(void)
 {
 #if defined(GLX_USE_TLS)
    return _glapi_tls_Context;
-#elif defined(THREADS)
-   if (ThreadSafe) {
-      return _glthread_GetTSD(&ContextTSD);
-   }
-   else {
-      return _glapi_Context;
-   }
 #else
    return _glapi_Context;
 #endif
@@ -341,7 +304,7 @@ _glapi_set_dispatch(struct _glapi_table *dispatch)
    _glapi_tls_Dispatch = dispatch;
 #elif defined(THREADS)
    _glthread_SetTSD(&_gl_DispatchTSD, (void *) dispatch);
-   _glapi_Dispatch = (ThreadSafe) ? NULL : dispatch;
+   _glapi_Dispatch = dispatch;
 #else /*THREADS*/
    _glapi_Dispatch = dispatch;
 #endif /*THREADS*/
@@ -358,10 +321,6 @@ _glapi_get_dispatch(void)
    struct _glapi_table * api;
 #if defined(GLX_USE_TLS)
    api = _glapi_tls_Dispatch;
-#elif defined(THREADS)
-   api = (ThreadSafe)
-     ? (struct _glapi_table *) _glthread_GetTSD(&_gl_DispatchTSD)
-     : _glapi_Dispatch;
 #else
    api = _glapi_Dispatch;
 #endif
-- 
1.7.3.5



More information about the xorg-devel mailing list