[Mesa-dev] [PATCH 2/2] mapi: use the C11 thrd_current/thrd_equal

Emil Velikov emil.l.velikov at gmail.com
Thu Apr 20 14:15:21 UTC 2017


From: Emil Velikov <emil.velikov at collabora.com>

As of earlier commit the implementations do the correct thing, so
there's no need to have the PTHREAD/WIN32 specifics in the current code.

Cc: Brian Paul <brianp at vmware.com>
Cc: José Fonseca <jfonseca at vmware.com>
Signed-off-by: Emil Velikov <emil.velikov at collabora.com>
---
There's an open question about how lightweight GetCurrentThread +
GetThreadId is wrt GetCurrentThreadId. If anyone can share their input
and/or preference I'm all for it.
---
 src/mapi/u_current.c | 42 +++---------------------------------------
 1 file changed, 3 insertions(+), 39 deletions(-)

diff --git a/src/mapi/u_current.c b/src/mapi/u_current.c
index 7e7e275f2e3..1c568a2ff26 100644
--- a/src/mapi/u_current.c
+++ b/src/mapi/u_current.c
@@ -145,42 +145,6 @@ u_current_init_tsd(void)
 static mtx_t ThreadCheckMutex = _MTX_INITIALIZER_NP;
 
 
-#ifdef _WIN32
-typedef DWORD thread_id;
-#else
-typedef thrd_t thread_id;
-#endif
-
-
-static inline thread_id
-get_thread_id(void)
-{
-   /*
-    * XXX: Callers of of this function assume it is a lightweight function.
-    * But unfortunately C11's thrd_current() gives no such guarantees.  In
-    * fact, it's pretty hard to have a compliant implementation of
-    * thrd_current() on Windows with such characteristics.  So for now, we
-    * side-step this mess and use Windows thread primitives directly here.
-    */
-#ifdef _WIN32
-   return GetCurrentThreadId();
-#else
-   return thrd_current();
-#endif
-}
-
-
-static inline int
-thread_id_equal(thread_id t1, thread_id t2)
-{
-#ifdef _WIN32
-   return t1 == t2;
-#else
-   return thrd_equal(t1, t2);
-#endif
-}
-
-
 /**
  * We should call this periodically from a function such as glXMakeCurrent
  * in order to test if multiple threads are being used.
@@ -188,7 +152,7 @@ thread_id_equal(thread_id t1, thread_id t2)
 void
 u_current_init(void)
 {
-   static thread_id knownID;
+   static thrd_t knownID;
    static int firstCall = 1;
 
    if (ThreadSafe)
@@ -198,10 +162,10 @@ u_current_init(void)
    if (firstCall) {
       u_current_init_tsd();
 
-      knownID = get_thread_id();
+      knownID = thrd_current();
       firstCall = 0;
    }
-   else if (!thread_id_equal(knownID, get_thread_id())) {
+   else if (!thrd_equal(knownID, thrd_current())) {
       ThreadSafe = 1;
       u_current_set_table(NULL);
       u_current_set_context(NULL);
-- 
2.12.2



More information about the mesa-dev mailing list