[Xquartz-changes] xserver: Branch 'master' - 6 commits

Jeremy Huddleston jeremyhu at freedesktop.org
Sat Apr 23 13:00:19 PDT 2011


 hw/xquartz/Makefile.am      |    6 -
 hw/xquartz/X11Application.m |    3 
 hw/xquartz/darwin.h         |    4 -
 hw/xquartz/darwinEvents.c   |    8 --
 hw/xquartz/quartz.c         |   10 +-
 hw/xquartz/quartz.h         |    2 
 hw/xquartz/quartzKeyboard.c |    2 
 hw/xquartz/quartzStartup.c  |    5 -
 hw/xquartz/threadSafety.c   |   78 --------------------
 hw/xquartz/threadSafety.h   |   56 --------------
 hw/xquartz/xpr/xpr.h        |    2 
 hw/xquartz/xpr/xprEvent.c   |    2 
 hw/xquartz/xpr/xprFrame.c   |  167 ++++++++++++++++----------------------------
 os/backtrace.c              |   19 +----
 14 files changed, 84 insertions(+), 280 deletions(-)

New commits:
commit fd804c9b4ef41e2b5d8065bf520ae22fc08d957a
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 12:55:39 2011 -0700

    XQuartz: xpr: Use a dispatch serial queue rather than pthread mutexes for window_hash
    
    Additionally removes some dead code and fixes double-locking in
    xprIsX11Window.  xprIsX11Window doesn't need to do any locking because
    those resources are protected by the called functions themselves.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/X11Application.m b/hw/xquartz/X11Application.m
index e56bf0c..ddfa7f3 100644
--- a/hw/xquartz/X11Application.m
+++ b/hw/xquartz/X11Application.m
@@ -237,8 +237,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
                 
                 if ([self isActive]) {
                     [self deactivate];
-                    if (!_x_active && quartzProcs->IsX11Window([e window],
-                                                               [e windowNumber]))
+                    if (!_x_active && quartzProcs->IsX11Window([e windowNumber]))
                         [self activateX:YES];
                 }
             }
diff --git a/hw/xquartz/quartz.h b/hw/xquartz/quartz.h
index 67a7919..0a9c47a 100644
--- a/hw/xquartz/quartz.h
+++ b/hw/xquartz/quartz.h
@@ -70,7 +70,7 @@ typedef void (*UpdateScreenProc)(ScreenPtr pScreen);
 /*
  * Rootless helper functions
  */
-typedef Bool (*IsX11WindowProc)(void *nsWindow, int windowNumber);
+typedef Bool (*IsX11WindowProc)(int windowNumber);
 typedef void (*HideWindowsProc)(Bool hide);
 
 /*
diff --git a/hw/xquartz/xpr/xpr.h b/hw/xquartz/xpr/xpr.h
index af1a90c..ebd89de 100644
--- a/hw/xquartz/xpr/xpr.h
+++ b/hw/xquartz/xpr/xpr.h
@@ -38,7 +38,7 @@ Bool QuartzModeBundleInit(void);
 void AppleDRIExtensionInit(void);
 void xprAppleWMInit(void);
 Bool xprInit(ScreenPtr pScreen);
-Bool xprIsX11Window(void *nsWindow, int windowNumber);
+Bool xprIsX11Window(int windowNumber);
 WindowPtr xprGetXWindow(xp_window_id wid);
 
 void xprHideWindows(Bool hide);
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index f0e9a89..066cc0f 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -43,7 +43,11 @@
 #include "windowstr.h"
 #include "quartz.h"
 
+#ifdef HAVE_LIBDISPATCH
+#include <dispatch/dispatch.h>
+#else
 #include <pthread.h>
+#endif
 
 #define DEFINE_ATOM_HELPER(func,atom_name)                      \
 static Atom func (void) {                                       \
@@ -61,10 +65,12 @@ DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
 /* Maps xp_window_id -> RootlessWindowRec */
 static x_hash_table *window_hash;
 
-/* Need to guard window_hash since xprGetXWindowFromAppKit and xprIsX11Window
- * can be called from any thread.
- */
+/* Need to guard window_hash since xprIsX11Window can be called from any thread. */
+#ifdef HAVE_LIBDISPATCH
+static dispatch_queue_t window_hash_serial_q;
+#else
 static pthread_mutex_t window_hash_mutex;
+#endif
 
 /* Prototypes for static functions */
 static Bool xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
@@ -181,9 +187,15 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
         return FALSE;
     }
 
+#ifdef HAVE_LIBDISPATCH
+    dispatch_async(window_hash_serial_q, ^{
+        x_hash_table_insert(window_hash, pFrame->wid, pFrame);
+    });
+#else
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_insert(window_hash, pFrame->wid, pFrame);
     pthread_mutex_unlock(&window_hash_mutex);
+#endif
 
     xprSetNativeProperty(pFrame);
 
@@ -199,9 +211,15 @@ xprDestroyFrame(RootlessFrameID wid)
 {
     xp_error err;
 
+#ifdef HAVE_LIBDISPATCH
+    dispatch_async(window_hash_serial_q, ^{
+        x_hash_table_remove(window_hash, wid);
+    });
+#else
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_remove(window_hash, wid);
     pthread_mutex_unlock(&window_hash_mutex);
+#endif
 
     err = xp_destroy_window(x_cvt_vptr_to_uint(wid));
     if (err != Success)
@@ -253,6 +271,9 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
     xp_window_changes wc;
     unsigned int mask = XP_STACKING;
+#ifdef HAVE_LIBDISPATCH
+    __block
+#endif
     RootlessWindowRec *winRec;
 
     /* Stack frame below nextWid it if it exists, or raise
@@ -266,8 +287,16 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
         wc.sibling = x_cvt_vptr_to_uint(nextWid);
     }
 
+#ifdef HAVE_LIBDISPATCH
+    dispatch_sync(window_hash_serial_q, ^{
+        winRec = x_hash_table_lookup(window_hash, wid, NULL);
+    });
+#else
+    pthread_mutex_lock(&window_hash_mutex);
     winRec = x_hash_table_lookup(window_hash, wid, NULL);
-
+    pthread_mutex_unlock(&window_hash_mutex);
+#endif
+    
     if(winRec) {
         if(XQuartzIsRootless)
             wc.window_level = normal_window_levels[winRec->level];
@@ -447,8 +476,12 @@ xprInit(ScreenPtr pScreen)
     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
 
     assert((window_hash = x_hash_table_new(NULL, NULL, NULL, NULL)));
+#ifdef HAVE_LIBDISPATCH
+    assert((window_hash_serial_q = dispatch_queue_create(LAUNCHD_ID_PREFIX".X11.xpr_window_hash", NULL)));
+#else
     assert(0 == pthread_mutex_init(&window_hash_mutex, NULL));
-
+#endif
+    
     return TRUE;
 }
 
@@ -460,60 +493,36 @@ xprInit(ScreenPtr pScreen)
 WindowPtr
 xprGetXWindow(xp_window_id wid)
 {
+#ifdef HAVE_LIBDISPATCH
+    RootlessWindowRec *winRec __block;
+    dispatch_sync(window_hash_serial_q, ^{
+        winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
+    });
+#else
     RootlessWindowRec *winRec;
-
-    winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
-
-    return winRec != NULL ? winRec->win : NULL;
-}
-
-#ifdef UNUSED_CODE
-/*
- * Given the id of a physical window, try to find the top-level (or root)
- * X window that it represents.
- */
-WindowPtr
-xprGetXWindowFromAppKit(int windowNumber)
-{
-    RootlessWindowRec *winRec;
-    Bool ret;
-    xp_window_id wid;
-
     pthread_mutex_lock(&window_hash_mutex);
-
-    if (xp_lookup_native_window(windowNumber, &wid))
-        ret = xprGetXWindow(wid) != NULL;
-    else
-        ret = FALSE;
-
-    pthread_mutex_unlock(&window_hash_mutex);
-
-    if (!ret) return NULL;
     winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
+    pthread_mutex_unlock(&window_hash_mutex);
+#endif
 
     return winRec != NULL ? winRec->win : NULL;
 }
-#endif
 
 /*
  * The windowNumber is an AppKit window number. Returns TRUE if xpr is
  * displaying a window with that number.
  */
 Bool
-xprIsX11Window(void *nsWindow, int windowNumber)
+xprIsX11Window(int windowNumber)
 {
     Bool ret;
     xp_window_id wid;
 
-    pthread_mutex_lock(&window_hash_mutex);
-
     if (xp_lookup_native_window(windowNumber, &wid))
         ret = xprGetXWindow(wid) != NULL;
     else
         ret = FALSE;
 
-    pthread_mutex_unlock(&window_hash_mutex);
-
     return ret;
 }
 
commit a03dd2de96af3b71b58afaf11296c07bed7dee1b
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 12:11:39 2011 -0700

    XQuartz: xpr: Initialize window_hash in xprInit
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index efb3737..f0e9a89 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -1,7 +1,7 @@
 /*
  * Xplugin rootless implementation frame functions
  *
- * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2002-2011 Apple Computer, Inc. All rights reserved.
  * Copyright (c) 2003 Torrey T. Lyons. All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -35,7 +35,6 @@
 #include "rootlessCommon.h"
 #include <Xplugin.h>
 #include "x-hash.h"
-#include "x-list.h"
 #include "applewmExt.h"
 
 #include "propertyst.h"
@@ -61,6 +60,10 @@ DEFINE_ATOM_HELPER(xa_native_window_id, "_NATIVE_WINDOW_ID")
 
 /* Maps xp_window_id -> RootlessWindowRec */
 static x_hash_table *window_hash;
+
+/* Need to guard window_hash since xprGetXWindowFromAppKit and xprIsX11Window
+ * can be called from any thread.
+ */
 static pthread_mutex_t window_hash_mutex;
 
 /* Prototypes for static functions */
@@ -178,12 +181,6 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
         return FALSE;
     }
 
-    if (window_hash == NULL)
-    {
-        window_hash = x_hash_table_new(NULL, NULL, NULL, NULL);
-        pthread_mutex_init(&window_hash_mutex, NULL);
-    }
-
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_insert(window_hash, pFrame->wid, pFrame);
     pthread_mutex_unlock(&window_hash_mutex);
@@ -256,6 +253,7 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
     xp_window_changes wc;
     unsigned int mask = XP_STACKING;
+    RootlessWindowRec *winRec;
 
     /* Stack frame below nextWid it if it exists, or raise
        frame above everything otherwise. */
@@ -268,18 +266,16 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
         wc.sibling = x_cvt_vptr_to_uint(nextWid);
     }
 
-    if(window_hash) {
-        RootlessWindowRec *winRec = x_hash_table_lookup(window_hash, wid, NULL);
-
-        if(winRec) {
-            if(XQuartzIsRootless)
-                wc.window_level = normal_window_levels[winRec->level];
-            else if(XQuartzShieldingWindowLevel)
-                wc.window_level = XQuartzShieldingWindowLevel + 1;
-            else
-                wc.window_level = rooted_window_levels[winRec->level];
-            mask |= XP_WINDOW_LEVEL;
-        }
+    winRec = x_hash_table_lookup(window_hash, wid, NULL);
+
+    if(winRec) {
+        if(XQuartzIsRootless)
+            wc.window_level = normal_window_levels[winRec->level];
+        else if(XQuartzShieldingWindowLevel)
+            wc.window_level = XQuartzShieldingWindowLevel + 1;
+        else
+            wc.window_level = rooted_window_levels[winRec->level];
+        mask |= XP_WINDOW_LEVEL;
     }
 
     xprConfigureWindow(x_cvt_vptr_to_uint(wid), mask, &wc);
@@ -450,6 +446,9 @@ xprInit(ScreenPtr pScreen)
     rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
 
+    assert((window_hash = x_hash_table_new(NULL, NULL, NULL, NULL)));
+    assert(0 == pthread_mutex_init(&window_hash_mutex, NULL));
+
     return TRUE;
 }
 
@@ -463,9 +462,6 @@ xprGetXWindow(xp_window_id wid)
 {
     RootlessWindowRec *winRec;
 
-    if (window_hash == NULL)
-        return NULL;
-
     winRec = x_hash_table_lookup(window_hash, x_cvt_uint_to_vptr(wid), NULL);
 
     return winRec != NULL ? winRec->win : NULL;
@@ -483,11 +479,6 @@ xprGetXWindowFromAppKit(int windowNumber)
     Bool ret;
     xp_window_id wid;
 
-    if (window_hash == NULL)
-        return FALSE;
-
-    /* need to lock, since this function can be called by any thread */
-
     pthread_mutex_lock(&window_hash_mutex);
 
     if (xp_lookup_native_window(windowNumber, &wid))
@@ -514,11 +505,6 @@ xprIsX11Window(void *nsWindow, int windowNumber)
     Bool ret;
     xp_window_id wid;
 
-    if (window_hash == NULL)
-        return FALSE;
-
-    /* need to lock, since this function can be called by any thread */
-
     pthread_mutex_lock(&window_hash_mutex);
 
     if (xp_lookup_native_window(windowNumber, &wid))
commit 423963468cf6f8ce5a55c25b60286b6fe22bcb66
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 11:55:49 2011 -0700

    XQuartz: Use a lighter spinlock instead of a pthread_mutex_t in QuartzScreenSaver
    
    Currently, we only end up here through a call to QuartzShowFullscreen, and
    this is always on the same thread.  Future changes (such as further
    incorporating libdispatch) may allow this to change, but contention will
    remain minimal since the call is infrequent and it is short held.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/quartz.c b/hw/xquartz/quartz.c
index 4b72a89..eb92d4a 100644
--- a/hw/xquartz/quartz.c
+++ b/hw/xquartz/quartz.c
@@ -62,7 +62,7 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <IOKit/pwr_mgt/IOPMLib.h>
-#include <pthread.h>
+#include <libkern/OSAtomic.h>
 #include <signal.h>
 
 #include <rootlessCommon.h>
@@ -279,10 +279,10 @@ static void pokeActivityCallback(CFRunLoopTimerRef timer, void *info) {
 static void QuartzScreenSaver(int state) {
     static CFRunLoopTimerRef pokeActivityTimer = NULL;
     static CFRunLoopTimerContext pokeActivityContext = { 0, NULL, NULL, NULL, NULL };
-    static pthread_mutex_t pokeActivityMutex = PTHREAD_MUTEX_INITIALIZER;
+    static OSSpinLock pokeActivitySpinLock = 0;
+
+    OSSpinLockLock(&pokeActivitySpinLock);
 
-    pthread_mutex_lock(&pokeActivityMutex);
-    
     if(state) {
         if(pokeActivityTimer == NULL)
             goto QuartzScreenSaverEnd;
@@ -303,7 +303,7 @@ static void QuartzScreenSaver(int state) {
         CFRunLoopAddTimer(CFRunLoopGetMain(), pokeActivityTimer, kCFRunLoopCommonModes);
     }
 QuartzScreenSaverEnd:
-    pthread_mutex_unlock(&pokeActivityMutex);
+    OSSpinLockUnlock(&pokeActivitySpinLock);
 }
 
 void QuartzShowFullscreen(int state) {
commit 5fd2d7807c4479b951f3e71953bdcaea99b1aaa5
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 01:48:25 2011 -0700

    XQuartz: Remove the threadSafety dead-ish code
    
    It's been a few years now since we've needed this to debug thread
    boundaries, so punt it out to clean up the namespace polution.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/Makefile.am b/hw/xquartz/Makefile.am
index 61b04e0..76f624d 100644
--- a/hw/xquartz/Makefile.am
+++ b/hw/xquartz/Makefile.am
@@ -33,8 +33,7 @@ libXquartz_la_SOURCES = \
 	quartzCocoa.m \
 	quartzKeyboard.c \
 	quartzStartup.c \
-	quartzRandR.c \
-	threadSafety.c
+	quartzRandR.c
 
 EXTRA_DIST = \
 	X11Application.h \
@@ -50,5 +49,4 @@ EXTRA_DIST = \
 	quartzKeyboard.h \
 	quartzRandR.h \
 	sanitizedCarbon.h \
-	sanitizedCocoa.h \
-	threadSafety.h
+	sanitizedCocoa.h
diff --git a/hw/xquartz/darwin.h b/hw/xquartz/darwin.h
index 3602257..3ba5d82 100644
--- a/hw/xquartz/darwin.h
+++ b/hw/xquartz/darwin.h
@@ -34,8 +34,6 @@
 #include <X11/extensions/XKB.h>
 #include <assert.h>
 
-#include "threadSafety.h"
-
 #include "darwinfb.h"
 
 // From darwin.c
@@ -80,7 +78,7 @@ extern int              darwinMainScreenY;
 #ifdef ENABLE_DEBUG_LOG
 extern FILE *debug_log_fp;
 #define DEBUG_LOG_NAME "x11-debug.txt"
-#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%s:%d " msg, threadSafetyID(pthread_self()), __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
+#define DEBUG_LOG(msg, args...) if (debug_log_fp) fprintf(debug_log_fp, "%s:%s:%d " msg, __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
 #else
 #define DEBUG_LOG(msg, args...) 
 #endif
diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 5bcee04..f3e1225 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -197,8 +197,6 @@ static void DarwinUpdateModifiers(
 static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) {
     XQuartzEvent *e = &(ie->xquartz_event);
 
-    TA_SERVER();
-
     switch(e->subtype) {
         case kXquartzControllerNotify:
             DEBUG_LOG("kXquartzControllerNotify\n");
@@ -381,8 +379,6 @@ void ProcessInputEvents(void) {
     char nullbyte;
 	int x = sizeof(nullbyte);
     
-    TA_SERVER();
-
     mieqProcessInputEvents();
 
     // Empty the signaling pipe
diff --git a/hw/xquartz/quartzKeyboard.c b/hw/xquartz/quartzKeyboard.c
index 54f709a..3ab5d52 100644
--- a/hw/xquartz/quartzKeyboard.c
+++ b/hw/xquartz/quartzKeyboard.c
@@ -56,8 +56,6 @@
 
 #include "X11Application.h"
 
-#include "threadSafety.h"
-
 #ifdef NDEBUG
 #undef NDEBUG
 #include <assert.h>
diff --git a/hw/xquartz/quartzStartup.c b/hw/xquartz/quartzStartup.c
index 36c8182..00a9e48 100644
--- a/hw/xquartz/quartzStartup.c
+++ b/hw/xquartz/quartzStartup.c
@@ -84,10 +84,7 @@ void QuartzInitServer(int argc, char **argv, char **envp) {
     args->argv = argv;
     args->envp = envp;
     
-    APPKIT_THREAD_ID = pthread_self();
-    SERVER_THREAD_ID = create_thread(server_thread, args);
-
-    if (!SERVER_THREAD_ID) {
+    if (!create_thread(server_thread, args)) {
         FatalError("can't create secondary thread\n");
     }
 }
diff --git a/hw/xquartz/threadSafety.c b/hw/xquartz/threadSafety.c
deleted file mode 100644
index 85f85bd..0000000
--- a/hw/xquartz/threadSafety.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2008 Apple, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifdef HAVE_DIX_CONFIG_H
-#include <dix-config.h>
-#endif
-
-#include "threadSafety.h"
-#include "os.h"
-
-pthread_t APPKIT_THREAD_ID;
-pthread_t SERVER_THREAD_ID;
-
-#include <AvailabilityMacros.h>
-
-#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
-#include <execinfo.h>
-
-void spewCallStack(void) {
-    void* callstack[128];
-    int i, frames = backtrace(callstack, 128);
-    char** strs = backtrace_symbols(callstack, frames);
-    
-    for (i = 0; i < frames; ++i) {
-        ErrorF("%s\n", strs[i]);
-    }
-    
-    free(strs);
-}
-#else
-void spewCallStack(void) {
-	return;
-}
-#endif
-
-void _threadSafetyAssert(pthread_t tid, const char *file, const char *fun, int line) {
-    if(pthread_equal(pthread_self(), tid))
-        return;
-    
-    /* NOOOO! */
-    ErrorF("Thread Assertion Failed: self=%s, expected=%s\n%s:%s:%d\n",
-           threadSafetyID(pthread_self()), threadSafetyID(tid),
-           file, fun, line);
-    spewCallStack();
-}
-
-const char *threadSafetyID(pthread_t tid) {
-    if(pthread_equal(tid, APPKIT_THREAD_ID)) {
-        return "Appkit Thread";
-    } else if(pthread_equal(tid, SERVER_THREAD_ID)) {
-        return "Xserver Thread";
-    } else {        
-        return "Unknown Thread";
-    }
-}
diff --git a/hw/xquartz/threadSafety.h b/hw/xquartz/threadSafety.h
deleted file mode 100644
index 3ff9eaf..0000000
--- a/hw/xquartz/threadSafety.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Copyright (C) 2008 Apple, Inc.
- *
- * Permission is hereby granted, free of charge, to any person obtaining a
- * copy of this software and associated documentation files (the "Software"),
- * to deal in the Software without restriction, including without limitation
- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
- * and/or sell copies of the Software, and to permit persons to whom the
- * Software is furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
- * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
- * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- * DEALINGS IN THE SOFTWARE.
- *
- * Except as contained in this notice, the name(s) of the above copyright
- * holders shall not be used in advertising or otherwise to promote the sale,
- * use or other dealings in this Software without prior written authorization.
- */
-
-#ifndef _XQ_THREAD_SAFETY_H_
-#define _XQ_THREAD_SAFETY_H_
-
-#define DEBUG_THREADS 1
-
-#include <pthread.h>
-
-extern pthread_t APPKIT_THREAD_ID;
-extern pthread_t SERVER_THREAD_ID;
-
-/* Dump the call stack */
-void spewCallStack(void);
-
-/* Print message to ErrorF if we're in the wrong thread */
-void _threadSafetyAssert(pthread_t tid, const char *file, const char *fun, int line);
-
-/* Get a string that identifies our thread nicely */
-const char *threadSafetyID(pthread_t tid);
-
-#define threadSafetyAssert(tid) _threadSafetyAssert(tid, __FILE__, __FUNCTION__, __LINE__)
-
-#ifdef DEBUG_THREADS
-#define TA_APPKIT() threadSafetyAssert(APPKIT_THREAD_ID)
-#define TA_SERVER() threadSafetyAssert(SERVER_THREAD_ID)
-#else
-#define TA_SERVER() 
-#define TA_APPKIT() 
-#endif
-
-#endif /* _XQ_THREAD_SAFETY_H_ */
diff --git a/hw/xquartz/xpr/xprEvent.c b/hw/xquartz/xpr/xprEvent.c
index 342b54c..cc86c47 100644
--- a/hw/xquartz/xpr/xprEvent.c
+++ b/hw/xquartz/xpr/xprEvent.c
@@ -57,8 +57,6 @@
 #include "xprEvent.h"
 
 Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev) {
-    TA_SERVER();
-    
     switch(e->subtype) {
         case kXquartzWindowState:
             DEBUG_LOG("kXquartzWindowState\n");
diff --git a/hw/xquartz/xpr/xprFrame.c b/hw/xquartz/xpr/xprFrame.c
index 15598e9..efb3737 100644
--- a/hw/xquartz/xpr/xprFrame.c
+++ b/hw/xquartz/xpr/xprFrame.c
@@ -44,8 +44,6 @@
 #include "windowstr.h"
 #include "quartz.h"
 
-#include "threadSafety.h"
-
 #include <pthread.h>
 
 #define DEFINE_ATOM_HELPER(func,atom_name)                      \
@@ -93,8 +91,6 @@ static inline xp_error
 xprConfigureWindow(xp_window_id id, unsigned int mask,
                    const xp_window_changes *values)
 {
-    TA_SERVER();
-
     return xp_configure_window(id, mask, values);
 }
 
@@ -106,8 +102,6 @@ xprSetNativeProperty(RootlessWindowPtr pFrame)
     unsigned int native_id;
     long data;
 
-    TA_SERVER();
-    
     err = xp_get_native_window(x_cvt_vptr_to_uint(pFrame->wid), &native_id);
     if (err == Success)
     {
@@ -137,8 +131,6 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
     unsigned int mask = 0;
     xp_error err;
 
-    TA_SERVER();
-    
     wc.x = newX;
     wc.y = newY;
     wc.width = pFrame->width;
@@ -209,8 +201,7 @@ static void
 xprDestroyFrame(RootlessFrameID wid)
 {
     xp_error err;
-    TA_SERVER();
-    
+
     pthread_mutex_lock(&window_hash_mutex);
     x_hash_table_remove(window_hash, wid);
     pthread_mutex_unlock(&window_hash_mutex);
@@ -229,8 +220,6 @@ xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     wc.x = newX;
     wc.y = newY;
     //    ErrorF("xprMoveFrame(%d, %p, %d, %d)\n", wid, pScreen, newX, newY);
@@ -248,8 +237,6 @@ xprResizeFrame(RootlessFrameID wid, ScreenPtr pScreen,
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     wc.x = newX;
     wc.y = newY;
     wc.width = newW;
@@ -270,8 +257,6 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
     xp_window_changes wc;
     unsigned int mask = XP_STACKING;
 
-    TA_SERVER();
-    
     /* Stack frame below nextWid it if it exists, or raise
        frame above everything otherwise. */
 
@@ -309,8 +294,6 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     if (pShape != NULL)
     {
         wc.shape_nrects = RegionNumRects(pShape);
@@ -336,8 +319,6 @@ xprUnmapFrame(RootlessFrameID wid)
 {
     xp_window_changes wc;
 
-    TA_SERVER();
-    
     wc.stack_mode = XP_UNMAPPED;
     wc.sibling = 0;
 
@@ -356,8 +337,6 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
     unsigned int rowbytes[2];
     xp_error err;
 
-    TA_SERVER();
-    
     err = xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, NULL);
     if (err != Success)
         FatalError("Could not lock window %i for drawing.", (int)x_cvt_vptr_to_uint(wid));
@@ -374,8 +353,7 @@ static void
 xprStopDrawing(RootlessFrameID wid, Bool flush)
 {
     xp_error err;
-    TA_SERVER();
-    
+
     err = xp_unlock_window(x_cvt_vptr_to_uint(wid), flush);
     if(err != Success)
         FatalError("Could not unlock window %i after drawing.", (int)x_cvt_vptr_to_uint(wid));
@@ -388,8 +366,6 @@ xprStopDrawing(RootlessFrameID wid, Bool flush)
 static void
 xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
 {
-    TA_SERVER();
-    
     xp_flush_window(x_cvt_vptr_to_uint(wid));
 }
 
@@ -401,8 +377,6 @@ static void
 xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
                int shift_x, int shift_y)
 {
-    TA_SERVER();
-    
     xp_mark_window(x_cvt_vptr_to_uint(wid), nrects, rects, shift_x, shift_y);
 }
 
@@ -416,8 +390,6 @@ xprSwitchWindow(RootlessWindowPtr pFrame, WindowPtr oldWin)
 {
     DeleteProperty(serverClient, oldWin, xa_native_window_id());
 
-    TA_SERVER();
-    
     xprSetNativeProperty(pFrame);
 }
 
@@ -429,8 +401,6 @@ static Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
 {
     WindowPtr pWin = pFrame->win;
 
-    TA_SERVER();
-    
     return AppleWMDoReorderWindow(pWin);
 }
 
@@ -443,8 +413,6 @@ static void
 xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
               int dx, int dy)
 {
-    TA_SERVER();
-    
     xp_copy_window(x_cvt_vptr_to_uint(wid), x_cvt_vptr_to_uint(wid),
                    dstNrects, dstRects, dx, dy);
 }
@@ -479,8 +447,6 @@ xprInit(ScreenPtr pScreen)
 {
     RootlessInit(pScreen, &xprRootlessProcs);
 
-    TA_SERVER();
-    
     rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
     rootless_CopyWindow_threshold = xp_scroll_area_threshold;
 
@@ -578,8 +544,6 @@ xprHideWindows(Bool hide)
     int screen;
     WindowPtr pRoot, pWin;
 
-    TA_SERVER();
-    
     for (screen = 0; screen < screenInfo.numScreens; screen++) {
         RootlessFrameID prevWid = NULL;
         pRoot = screenInfo.screens[screen]->root;
commit f63419a78f35a856209b43ed8b51597a80be6bec
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 01:39:16 2011 -0700

    XQuartz: Use xorg_backtrace() instead of spewCallStack()
    
    Now that xorg_backtrace() produces pretty backtraces, we can use
    it instead.
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/hw/xquartz/darwinEvents.c b/hw/xquartz/darwinEvents.c
index 40d8a4e..5bcee04 100644
--- a/hw/xquartz/darwinEvents.c
+++ b/hw/xquartz/darwinEvents.c
@@ -113,7 +113,7 @@ void darwinEvents_lock(void) {
     if((err = pthread_mutex_lock(&mieq_lock))) {
         ErrorF("%s:%s:%d: Failed to lock mieq_lock: %d\n",
                __FILE__, __FUNCTION__, __LINE__, err);
-        spewCallStack();
+        xorg_backtrace();
     }
     if(darwinEvents == NULL) {
         pthread_cond_wait(&mieq_ready_cond, &mieq_lock);
@@ -126,7 +126,7 @@ void darwinEvents_unlock(void) {
     if((err = pthread_mutex_unlock(&mieq_lock))) {
         ErrorF("%s:%s:%d: Failed to unlock mieq_lock: %d\n",
                __FILE__, __FUNCTION__, __LINE__, err);
-        spewCallStack();
+        xorg_backtrace();
     }
 }
 
commit ce8295b6b3987fcac093f4e97de755f54d1eaeb1
Author: Jeremy Huddleston <jeremyhu at apple.com>
Date:   Sat Apr 23 01:12:17 2011 -0700

    os/backtrace: Use backtrace_symbols where available
    
    Signed-off-by: Jeremy Huddleston <jeremyhu at apple.com>

diff --git a/os/backtrace.c b/os/backtrace.c
index 7ca6dab..5ddb15c 100644
--- a/os/backtrace.c
+++ b/os/backtrace.c
@@ -37,21 +37,16 @@
 
 void xorg_backtrace(void)
 {
-    void *array[64];
-    const char *mod;
+    void *callstack[64];
     int size, i;
-    Dl_info info;
+    char **strs;
+
     ErrorF("\nBacktrace:\n");
-    size = backtrace(array, 64);
+    size = backtrace(callstack, 64);
+    strs = backtrace_symbols(callstack, size);
+
     for (i = 0; i < size; i++) {
-	dladdr(array[i], &info);
-	mod = (info.dli_fname && *info.dli_fname) ? info.dli_fname : "(vdso)";
-	if (info.dli_saddr)
-	    ErrorF("%d: %s (%s+0x%lx) [%p]\n", i, mod,
-		   info.dli_sname, (long unsigned int)((char *) array[i] - (char *) info.dli_saddr), array[i]);
-	else
-	    ErrorF("%d: %s (%p+0x%lx) [%p]\n", i, mod,
-		   info.dli_fbase, (long unsigned int)((char *) array[i] - (char *) info.dli_fbase), array[i]);
+        ErrorF("%s\n", strs[i]);
     }
 }
 


More information about the Xquartz-changes mailing list