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@apple.com>
This commit is contained in:
Jeremy Huddleston 2011-04-23 01:48:25 -07:00
parent a52c8078c9
commit 3e253c603b
9 changed files with 6 additions and 191 deletions

View File

@ -33,8 +33,7 @@ libXquartz_la_SOURCES = \
quartzCocoa.m \ quartzCocoa.m \
quartzKeyboard.c \ quartzKeyboard.c \
quartzStartup.c \ quartzStartup.c \
quartzRandR.c \ quartzRandR.c
threadSafety.c
EXTRA_DIST = \ EXTRA_DIST = \
X11Application.h \ X11Application.h \
@ -50,5 +49,4 @@ EXTRA_DIST = \
quartzKeyboard.h \ quartzKeyboard.h \
quartzRandR.h \ quartzRandR.h \
sanitizedCarbon.h \ sanitizedCarbon.h \
sanitizedCocoa.h \ sanitizedCocoa.h
threadSafety.h

View File

@ -34,8 +34,6 @@
#include <X11/extensions/XKB.h> #include <X11/extensions/XKB.h>
#include <assert.h> #include <assert.h>
#include "threadSafety.h"
#include "darwinfb.h" #include "darwinfb.h"
// From darwin.c // From darwin.c
@ -80,7 +78,7 @@ extern int darwinMainScreenY;
#ifdef ENABLE_DEBUG_LOG #ifdef ENABLE_DEBUG_LOG
extern FILE *debug_log_fp; extern FILE *debug_log_fp;
#define DEBUG_LOG_NAME "x11-debug.txt" #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 #else
#define DEBUG_LOG(msg, args...) #define DEBUG_LOG(msg, args...)
#endif #endif

View File

@ -197,8 +197,6 @@ static void DarwinUpdateModifiers(
static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) { static void DarwinEventHandler(int screenNum, InternalEvent *ie, DeviceIntPtr dev) {
XQuartzEvent *e = &(ie->xquartz_event); XQuartzEvent *e = &(ie->xquartz_event);
TA_SERVER();
switch(e->subtype) { switch(e->subtype) {
case kXquartzControllerNotify: case kXquartzControllerNotify:
DEBUG_LOG("kXquartzControllerNotify\n"); DEBUG_LOG("kXquartzControllerNotify\n");
@ -381,8 +379,6 @@ void ProcessInputEvents(void) {
char nullbyte; char nullbyte;
int x = sizeof(nullbyte); int x = sizeof(nullbyte);
TA_SERVER();
mieqProcessInputEvents(); mieqProcessInputEvents();
// Empty the signaling pipe // Empty the signaling pipe

View File

@ -56,8 +56,6 @@
#include "X11Application.h" #include "X11Application.h"
#include "threadSafety.h"
#ifdef NDEBUG #ifdef NDEBUG
#undef NDEBUG #undef NDEBUG
#include <assert.h> #include <assert.h>

View File

@ -84,10 +84,7 @@ void QuartzInitServer(int argc, char **argv, char **envp) {
args->argv = argv; args->argv = argv;
args->envp = envp; args->envp = envp;
APPKIT_THREAD_ID = pthread_self(); if (!create_thread(server_thread, args)) {
SERVER_THREAD_ID = create_thread(server_thread, args);
if (!SERVER_THREAD_ID) {
FatalError("can't create secondary thread\n"); FatalError("can't create secondary thread\n");
} }
} }

View File

@ -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";
}
}

View File

@ -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_ */

View File

@ -57,8 +57,6 @@
#include "xprEvent.h" #include "xprEvent.h"
Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev) { Bool QuartzModeEventHandler(int screenNum, XQuartzEvent *e, DeviceIntPtr dev) {
TA_SERVER();
switch(e->subtype) { switch(e->subtype) {
case kXquartzWindowState: case kXquartzWindowState:
DEBUG_LOG("kXquartzWindowState\n"); DEBUG_LOG("kXquartzWindowState\n");

View File

@ -44,8 +44,6 @@
#include "windowstr.h" #include "windowstr.h"
#include "quartz.h" #include "quartz.h"
#include "threadSafety.h"
#include <pthread.h> #include <pthread.h>
#define DEFINE_ATOM_HELPER(func,atom_name) \ #define DEFINE_ATOM_HELPER(func,atom_name) \
@ -93,8 +91,6 @@ static inline xp_error
xprConfigureWindow(xp_window_id id, unsigned int mask, xprConfigureWindow(xp_window_id id, unsigned int mask,
const xp_window_changes *values) const xp_window_changes *values)
{ {
TA_SERVER();
return xp_configure_window(id, mask, values); return xp_configure_window(id, mask, values);
} }
@ -106,8 +102,6 @@ xprSetNativeProperty(RootlessWindowPtr pFrame)
unsigned int native_id; unsigned int native_id;
long data; long data;
TA_SERVER();
err = xp_get_native_window(x_cvt_vptr_to_uint(pFrame->wid), &native_id); err = xp_get_native_window(x_cvt_vptr_to_uint(pFrame->wid), &native_id);
if (err == Success) if (err == Success)
{ {
@ -137,8 +131,6 @@ xprCreateFrame(RootlessWindowPtr pFrame, ScreenPtr pScreen,
unsigned int mask = 0; unsigned int mask = 0;
xp_error err; xp_error err;
TA_SERVER();
wc.x = newX; wc.x = newX;
wc.y = newY; wc.y = newY;
wc.width = pFrame->width; wc.width = pFrame->width;
@ -209,7 +201,6 @@ static void
xprDestroyFrame(RootlessFrameID wid) xprDestroyFrame(RootlessFrameID wid)
{ {
xp_error err; xp_error err;
TA_SERVER();
pthread_mutex_lock(&window_hash_mutex); pthread_mutex_lock(&window_hash_mutex);
x_hash_table_remove(window_hash, wid); x_hash_table_remove(window_hash, wid);
@ -229,8 +220,6 @@ xprMoveFrame(RootlessFrameID wid, ScreenPtr pScreen, int newX, int newY)
{ {
xp_window_changes wc; xp_window_changes wc;
TA_SERVER();
wc.x = newX; wc.x = newX;
wc.y = newY; wc.y = newY;
// ErrorF("xprMoveFrame(%d, %p, %d, %d)\n", wid, pScreen, newX, 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; xp_window_changes wc;
TA_SERVER();
wc.x = newX; wc.x = newX;
wc.y = newY; wc.y = newY;
wc.width = newW; wc.width = newW;
@ -270,8 +257,6 @@ static void xprRestackFrame(RootlessFrameID wid, RootlessFrameID nextWid) {
xp_window_changes wc; xp_window_changes wc;
unsigned int mask = XP_STACKING; unsigned int mask = XP_STACKING;
TA_SERVER();
/* Stack frame below nextWid it if it exists, or raise /* Stack frame below nextWid it if it exists, or raise
frame above everything otherwise. */ frame above everything otherwise. */
@ -309,8 +294,6 @@ xprReshapeFrame(RootlessFrameID wid, RegionPtr pShape)
{ {
xp_window_changes wc; xp_window_changes wc;
TA_SERVER();
if (pShape != NULL) if (pShape != NULL)
{ {
wc.shape_nrects = RegionNumRects(pShape); wc.shape_nrects = RegionNumRects(pShape);
@ -336,8 +319,6 @@ xprUnmapFrame(RootlessFrameID wid)
{ {
xp_window_changes wc; xp_window_changes wc;
TA_SERVER();
wc.stack_mode = XP_UNMAPPED; wc.stack_mode = XP_UNMAPPED;
wc.sibling = 0; wc.sibling = 0;
@ -356,8 +337,6 @@ xprStartDrawing(RootlessFrameID wid, char **pixelData, int *bytesPerRow)
unsigned int rowbytes[2]; unsigned int rowbytes[2];
xp_error err; xp_error err;
TA_SERVER();
err = xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, NULL); err = xp_lock_window(x_cvt_vptr_to_uint(wid), NULL, NULL, data, rowbytes, NULL);
if (err != Success) if (err != Success)
FatalError("Could not lock window %i for drawing.", (int)x_cvt_vptr_to_uint(wid)); FatalError("Could not lock window %i for drawing.", (int)x_cvt_vptr_to_uint(wid));
@ -374,7 +353,6 @@ static void
xprStopDrawing(RootlessFrameID wid, Bool flush) xprStopDrawing(RootlessFrameID wid, Bool flush)
{ {
xp_error err; xp_error err;
TA_SERVER();
err = xp_unlock_window(x_cvt_vptr_to_uint(wid), flush); err = xp_unlock_window(x_cvt_vptr_to_uint(wid), flush);
if(err != Success) if(err != Success)
@ -388,8 +366,6 @@ xprStopDrawing(RootlessFrameID wid, Bool flush)
static void static void
xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage) xprUpdateRegion(RootlessFrameID wid, RegionPtr pDamage)
{ {
TA_SERVER();
xp_flush_window(x_cvt_vptr_to_uint(wid)); xp_flush_window(x_cvt_vptr_to_uint(wid));
} }
@ -401,8 +377,6 @@ static void
xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects, xprDamageRects(RootlessFrameID wid, int nrects, const BoxRec *rects,
int shift_x, int shift_y) int shift_x, int shift_y)
{ {
TA_SERVER();
xp_mark_window(x_cvt_vptr_to_uint(wid), nrects, rects, shift_x, shift_y); 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()); DeleteProperty(serverClient, oldWin, xa_native_window_id());
TA_SERVER();
xprSetNativeProperty(pFrame); xprSetNativeProperty(pFrame);
} }
@ -429,8 +401,6 @@ static Bool xprDoReorderWindow(RootlessWindowPtr pFrame)
{ {
WindowPtr pWin = pFrame->win; WindowPtr pWin = pFrame->win;
TA_SERVER();
return AppleWMDoReorderWindow(pWin); return AppleWMDoReorderWindow(pWin);
} }
@ -443,8 +413,6 @@ static void
xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects, xprCopyWindow(RootlessFrameID wid, int dstNrects, const BoxRec *dstRects,
int dx, int dy) int dx, int dy)
{ {
TA_SERVER();
xp_copy_window(x_cvt_vptr_to_uint(wid), x_cvt_vptr_to_uint(wid), xp_copy_window(x_cvt_vptr_to_uint(wid), x_cvt_vptr_to_uint(wid),
dstNrects, dstRects, dx, dy); dstNrects, dstRects, dx, dy);
} }
@ -479,8 +447,6 @@ xprInit(ScreenPtr pScreen)
{ {
RootlessInit(pScreen, &xprRootlessProcs); RootlessInit(pScreen, &xprRootlessProcs);
TA_SERVER();
rootless_CopyBytes_threshold = xp_copy_bytes_threshold; rootless_CopyBytes_threshold = xp_copy_bytes_threshold;
rootless_CopyWindow_threshold = xp_scroll_area_threshold; rootless_CopyWindow_threshold = xp_scroll_area_threshold;
@ -578,8 +544,6 @@ xprHideWindows(Bool hide)
int screen; int screen;
WindowPtr pRoot, pWin; WindowPtr pRoot, pWin;
TA_SERVER();
for (screen = 0; screen < screenInfo.numScreens; screen++) { for (screen = 0; screen < screenInfo.numScreens; screen++) {
RootlessFrameID prevWid = NULL; RootlessFrameID prevWid = NULL;
pRoot = screenInfo.screens[screen]->root; pRoot = screenInfo.screens[screen]->root;