On Mon, Jul 13, 2009 at 03:14:37PM +0100, José Fonseca wrote:
> Your patches look good, with the exception of relying on
> _glthread_DECLARE_STATIC_MUTEX which is broken on windows, and windows
> too fits on the THREADS && !GLX_USE_TLS use case.
Oops...
> 
> So we need to fix _glthread_DECLARE_STATIC_MUTEX on windows first, or
> these lines should be added
> 
> #ifdef _WIN32
>   /* FIXME: _glthread_DECLARE_STATIC_MUTEX is broken on windows */
>   static int onetime = 0;
>   if(!onetime) {
>     _glthread_INIT_MUTEX(ThreadCheckMutex);
>     onetime = 1;
>   }
> #endif
> 
> Which re-introduces the race condition, but at least it prevents it from
> crashing on the first access to the ThreadCheckMutex. This until we find
> a proper way of implementing _glthread_DECLARE_STATIC_MUTEX on windows.
MSDN says that the behavior is undefined if a critical section is
initialized twice.  It is better to avoid the lock completely on
windows.  I have attached a patch for this.  Could you help me test it?
> Michal, I recall you mentioned some way of statically initializing
> CRITICAL_SECTIONs on windows, but I can't find anything on it on google.
> The only ways I can find are either using atomic operations on a flag,
> or using constructors/DLL_PROCESS_ATTACH etc.

-- 
Regards,
olv
>From 7cb1560ae640d0a36434ccc926869c417b0f05fa Mon Sep 17 00:00:00 2001
From: Chia-I Wu <olva...@gmail.com>
Date: Tue, 14 Jul 2009 13:17:25 +0800
Subject: [PATCH] Static mutex does not work on WIN32_THREADS.

This re-introduces the race in _glapi_check_multithread, but avoids a
crash on windows.

Signed-off-by: Chia-I Wu <olva...@gmail.com>
---
 src/mesa/glapi/glapi.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/src/mesa/glapi/glapi.c b/src/mesa/glapi/glapi.c
index 60b0299..2f90734 100644
--- a/src/mesa/glapi/glapi.c
+++ b/src/mesa/glapi/glapi.c
@@ -195,7 +195,16 @@ GLboolean _glapi_SingleThreaded = GL_FALSE;
 
 #if defined(THREADS)
 
+#ifdef WIN32_THREADS
+/* _glthread_DECLARE_STATIC_MUTEX is broken on windows.  There will be race! */
+#define CHECK_MULTITHREAD_LOCK()
+#define CHECK_MULTITHREAD_UNLOCK()
+#else
 _glthread_DECLARE_STATIC_MUTEX(ThreadCheckMutex);
+#define CHECK_MULTITHREAD_LOCK() _glthread_LOCK_MUTEX(ThreadCheckMutex)
+#define CHECK_MULTITHREAD_UNLOCK() _glthread_UNLOCK_MUTEX(ThreadCheckMutex)
+#endif
+
 GLboolean _glapi_SingleThreaded = GL_TRUE;  /**< In single-thread mode? */
 _glthread_TSD _gl_DispatchTSD;              /**< Per-thread dispatch pointer */
 static _glthread_TSD ContextTSD;            /**< Per-thread context pointer */
@@ -235,7 +244,7 @@ _glapi_check_multithread(void)
    if (!_glapi_SingleThreaded)
       return;
 
-   _glthread_LOCK_MUTEX(ThreadCheckMutex);
+   CHECK_MULTITHREAD_LOCK();
    if (firstCall) {
       /* initialize TSDs */
       (void) _glthread_GetTSD(&ContextTSD);
@@ -252,7 +261,7 @@ _glapi_check_multithread(void)
        */
       _glapi_SingleThreaded = GL_FALSE;
    }
-   _glthread_UNLOCK_MUTEX(ThreadCheckMutex);
+   CHECK_MULTITHREAD_UNLOCK();
 #endif
 }
 
-- 
1.6.2.4

------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Mesa3d-dev mailing list
Mesa3d-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mesa3d-dev

Reply via email to