xserver: Branch 'xorg-server-1.4-apple'

Jeremy Huddleston jeremyhu at kemper.freedesktop.org
Fri Apr 18 20:06:38 PDT 2008


 hw/xquartz/X11Application.m |    8 +++++---
 hw/xquartz/threadSafety.c   |   37 ++++++++++++++++++++++++++++++++++---
 hw/xquartz/threadSafety.h   |   20 +++++++++++++-------
 3 files changed, 52 insertions(+), 13 deletions(-)

New commits:
commit 49692925cc1476080e4f4d95d02404f026644683
Author: Jeremy Huddleston <jeremyhu at freedesktop.org>
Date:   Fri Apr 18 19:17:47 2008 -0700

    XQuartz: More thread debugging

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index 701e9c7..986771c 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -798,6 +798,7 @@ environment?", @"Startup xinitrc dialog");
 
 void X11ApplicationMain (int argc, const char **argv, void (*server_thread) (void *), void *server_arg) {
     NSAutoreleasePool *pool;
+    pthread_t tid;
 
 #ifdef DEBUG
     while (access ("/tmp/x11-block", F_OK) == 0) sleep (1);
@@ -823,10 +824,11 @@ void X11ApplicationMain (int argc, const char **argv, void (*server_thread) (voi
     aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
     NSMaxY([[NSScreen mainScreen] visibleFrame]);
   
-    APPKIT_THREAD = pthread_self();
-    SERVER_THREAD = create_thread (server_thread, server_arg);
+    threadSafetyAssign(APPKIT_THREAD_ID, pthread_self());
+    tid = create_thread(server_thread, server_arg);
+    threadSafetyAssign(SERVER_THREAD_ID, tid);
 
-    if (!SERVER_THREAD) {
+    if (!tid) {
         ErrorF("can't create secondary thread\n");
         exit (1);
     }
diff --git a/hw/xquartz/threadSafety.c b/hw/xquartz/threadSafety.c
index 7835de6..63111b9 100644
--- a/hw/xquartz/threadSafety.c
+++ b/hw/xquartz/threadSafety.c
@@ -33,8 +33,8 @@
 
 #include <execinfo.h>
 
-pthread_t SERVER_THREAD;
-pthread_t APPKIT_THREAD;
+#define TH_MAX 8
+static pthread_t threadSavetyThreads[TH_MAX];
 
 void spewCallStack(void) {
     void* callstack[128];
@@ -48,7 +48,19 @@ void spewCallStack(void) {
     free(strs);
 }
 
-void _threadAssert(pthread_t tid, const char *file, const char *fun, int line) {
+void threadSafetyAssign(unsigned id, pthread_t tid) {
+    if(id >= TH_MAX) {
+        return;
+    }
+    threadSavetyThreads[id] = tid;
+}
+
+void _threadSafetyAssert(unsigned id, const char *file, const char *fun, int line) {
+    if(id >= TH_MAX) {
+        return;
+    }
+    pthread_t tid = threadSavetyThreads[id];
+
     if(pthread_equal(pthread_self(), tid))
         return;
     
@@ -58,3 +70,22 @@ void _threadAssert(pthread_t tid, const char *file, const char *fun, int line) {
            file, fun, line);
     spewCallStack();
 }
+
+const char *threadSafetyID(pthread_t tid) {
+    size_t i;
+    for(i=0; i < TH_MAX && !pthread_equal(threadSavetyThreads[i], tid); i++);
+    
+    if(i == TH_MAX) {
+        return "Invalid Thread";
+    }
+    switch(i) {
+        case APPKIT_THREAD_ID:
+            return "Appkit Thread";
+        case  SERVER_THREAD_ID:
+            return "Xserver Thread";
+        case 3:
+            return "Xplugin xp_async_thread";
+        default:
+            return "Unknown Thread";
+    }
+}
diff --git a/hw/xquartz/threadSafety.h b/hw/xquartz/threadSafety.h
index ed2ad9f..a25e3cf 100644
--- a/hw/xquartz/threadSafety.h
+++ b/hw/xquartz/threadSafety.h
@@ -31,22 +31,28 @@
 
 #include <pthread.h>
 
-extern pthread_t SERVER_THREAD;
-extern pthread_t APPKIT_THREAD;
+#define APPKIT_THREAD_ID 0
+#define SERVER_THREAD_ID 1
 
-#define threadSafetyID(tid) (pthread_equal((tid), SERVER_THREAD) ? "X Server Thread" : "Appkit Thread")
+/* Set tid to be assigned to the passed threadSafety id
+ * id < 8
+ */
+void threadSafetyAssign(unsigned id, pthread_t tid);
 
 /* Dump the call stack */
 void spewCallStack(void);
 
 /* Print message to ErrorF if we're in the wrong thread */
-void _threadAssert(pthread_t tid, const char *file, const char *fun, int line);
+void _threadSafetyAssert(unsigned id, const char *file, const char *fun, int line);
+
+/* Get a string that identifies our thread nicely */
+const char *threadSafetyID(pthread_t tid);
 
-#define threadAssert(tid) _threadAssert(tid, __FILE__, __FUNCTION__, __LINE__)
+#define threadSafetyAssert(id) _threadSafetyAssert(id, __FILE__, __FUNCTION__, __LINE__)
 
 #ifdef DEBUG_THREADS
-#define TA_SERVER() threadAssert(SERVER_THREAD)
-#define TA_APPKIT() threadAssert(APPKIT_THREAD)
+#define TA_APPKIT() threadSafetyAssert(APPKIT_THREAD_ID)
+#define TA_SERVER() threadSafetyAssert(SERVER_THREAD_ID)
 #else
 #define TA_SERVER() 
 #define TA_APPKIT() 


More information about the xorg-commit mailing list