Mesa (master): mapi: _glthread_DECLARE_STATIC_MUTEX is not broken on Windows.

Jose Fonseca jrfonseca at kemper.freedesktop.org
Sun Mar 6 09:19:01 UTC 2011


Module: Mesa
Branch: master
Commit: b531b01b707370df2cf013fc18c70eda62f5b4be
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=b531b01b707370df2cf013fc18c70eda62f5b4be

Author: José Fonseca <jose.r.fonseca at gmail.com>
Date:   Sun Mar  6 09:11:59 2011 +0000

mapi: _glthread_DECLARE_STATIC_MUTEX is not broken on Windows.

---

 src/mapi/mapi/u_current.c |   12 ++----------
 src/mapi/mapi/u_thread.c  |    9 ++-------
 src/mapi/mapi/u_thread.h  |    2 +-
 3 files changed, 5 insertions(+), 18 deletions(-)

diff --git a/src/mapi/mapi/u_current.c b/src/mapi/mapi/u_current.c
index 7946d2a..21a07ab 100644
--- a/src/mapi/mapi/u_current.c
+++ b/src/mapi/mapi/u_current.c
@@ -144,15 +144,7 @@ u_current_init_tsd(void)
 /**
  * Mutex for multithread check.
  */
-#ifdef WIN32
-/* _glthread_DECLARE_STATIC_MUTEX is broken on windows.  There will be race! */
-#define CHECK_MULTITHREAD_LOCK()
-#define CHECK_MULTITHREAD_UNLOCK()
-#else
 u_mutex_declare_static(ThreadCheckMutex);
-#define CHECK_MULTITHREAD_LOCK() u_mutex_lock(ThreadCheckMutex)
-#define CHECK_MULTITHREAD_UNLOCK() u_mutex_unlock(ThreadCheckMutex)
-#endif
 
 /**
  * We should call this periodically from a function such as glXMakeCurrent
@@ -167,7 +159,7 @@ u_current_init(void)
    if (ThreadSafe)
       return;
 
-   CHECK_MULTITHREAD_LOCK();
+   u_mutex_lock(ThreadCheckMutex);
    if (firstCall) {
       u_current_init_tsd();
 
@@ -179,7 +171,7 @@ u_current_init(void)
       u_current_set(NULL);
       u_current_set_user(NULL);
    }
-   CHECK_MULTITHREAD_UNLOCK();
+   u_mutex_unlock(ThreadCheckMutex);
 }
 
 #else
diff --git a/src/mapi/mapi/u_thread.c b/src/mapi/mapi/u_thread.c
index 138db47..12e748f 100644
--- a/src/mapi/mapi/u_thread.c
+++ b/src/mapi/mapi/u_thread.c
@@ -113,11 +113,6 @@ u_tsd_set(struct u_tsd *tsd, void *ptr)
  */
 #ifdef WIN32
 
-static void InsteadOf_exit(int nCode)
-{
-   DWORD dwErr = GetLastError();
-}
-
 unsigned long
 u_thread_self(void)
 {
@@ -131,7 +126,7 @@ u_tsd_init(struct u_tsd *tsd)
    tsd->key = TlsAlloc();
    if (tsd->key == TLS_OUT_OF_INDEXES) {
       perror(INIT_TSD_ERROR);
-      InsteadOf_exit(-1);
+      exit(-1);
    }
    tsd->initMagic = INIT_MAGIC;
 }
@@ -168,7 +163,7 @@ u_tsd_set(struct u_tsd *tsd, void *ptr)
    }
    if (TlsSetValue(tsd->key, ptr) == 0) {
       perror(SET_TSD_ERROR);
-      InsteadOf_exit(-1);
+      exit(-1);
    }
 }
 
diff --git a/src/mapi/mapi/u_thread.h b/src/mapi/mapi/u_thread.h
index 92a0a39..1cc8be3 100644
--- a/src/mapi/mapi/u_thread.h
+++ b/src/mapi/mapi/u_thread.h
@@ -97,7 +97,7 @@ typedef CRITICAL_SECTION u_mutex;
 
 /* http://locklessinc.com/articles/pthreads_on_windows/ */
 #define u_mutex_declare_static(name) \
-   /* static */ u_mutex name = {(void*)-1, -1, 0, 0, 0, 0}
+   static u_mutex name = {(PCRITICAL_SECTION_DEBUG)-1, -1, 0, 0, 0, 0}
 
 #define u_mutex_init(name)    InitializeCriticalSection(&name)
 #define u_mutex_destroy(name) DeleteCriticalSection(&name)




More information about the mesa-commit mailing list