XQuartz: Added framework for asserting which thread we're in.
(cherry picked from commit 00beb982510e7a82d77e1f1d43e77c84d7bf74c2)
This commit is contained in:
parent
fa0645b452
commit
dbd4c03156
|
@ -34,7 +34,8 @@ libXquartz_la_SOURCES = \
|
||||||
quartzForeground.c \
|
quartzForeground.c \
|
||||||
quartzKeyboard.c \
|
quartzKeyboard.c \
|
||||||
quartzPasteboard.c \
|
quartzPasteboard.c \
|
||||||
quartzStartup.c
|
quartzStartup.c \
|
||||||
|
threadSafety.c
|
||||||
|
|
||||||
EXTRA_DIST = \
|
EXTRA_DIST = \
|
||||||
X11Application.h \
|
X11Application.h \
|
||||||
|
@ -50,4 +51,5 @@ EXTRA_DIST = \
|
||||||
quartzCommon.h \
|
quartzCommon.h \
|
||||||
quartzForeground.h \
|
quartzForeground.h \
|
||||||
quartzKeyboard.h \
|
quartzKeyboard.h \
|
||||||
quartzPasteboard.h
|
quartzPasteboard.h \
|
||||||
|
threadSafety.h
|
||||||
|
|
|
@ -738,7 +738,7 @@ void X11ApplicationShowHideMenubar (int state) {
|
||||||
[n release];
|
[n release];
|
||||||
}
|
}
|
||||||
|
|
||||||
static void * create_thread (void *func, void *arg) {
|
static pthread_t create_thread (void *func, void *arg) {
|
||||||
pthread_attr_t attr;
|
pthread_attr_t attr;
|
||||||
pthread_t tid;
|
pthread_t tid;
|
||||||
|
|
||||||
|
@ -748,7 +748,7 @@ static void * create_thread (void *func, void *arg) {
|
||||||
pthread_create (&tid, &attr, func, arg);
|
pthread_create (&tid, &attr, func, arg);
|
||||||
pthread_attr_destroy (&attr);
|
pthread_attr_destroy (&attr);
|
||||||
|
|
||||||
return (void *) tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void check_xinitrc (void) {
|
static void check_xinitrc (void) {
|
||||||
|
@ -819,7 +819,10 @@ void X11ApplicationMain (int argc, const char **argv, void (*server_thread) (voi
|
||||||
aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
|
aquaMenuBarHeight = NSHeight([[NSScreen mainScreen] frame]) -
|
||||||
NSMaxY([[NSScreen mainScreen] visibleFrame]);
|
NSMaxY([[NSScreen mainScreen] visibleFrame]);
|
||||||
|
|
||||||
if (!create_thread (server_thread, server_arg)) {
|
APPKIT_THREAD = pthread_self();
|
||||||
|
SERVER_THREAD = create_thread (server_thread, server_arg);
|
||||||
|
|
||||||
|
if (!SERVER_THREAD) {
|
||||||
ErrorF("can't create secondary thread\n");
|
ErrorF("can't create secondary thread\n");
|
||||||
exit (1);
|
exit (1);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#include <X11/extensions/XKB.h>
|
#include <X11/extensions/XKB.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#include "threadSafety.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *framebuffer;
|
void *framebuffer;
|
||||||
int x;
|
int x;
|
||||||
|
@ -123,7 +125,7 @@ void DarwinSendDDXEvent(int type, int argc, ...);
|
||||||
#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, "%x:%s:%s:%d " msg, 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:%s:%d " msg, threadSafetyID(pthread_self()), __FILE__, __FUNCTION__, __LINE__, ##args ); fflush(debug_log_fp);
|
||||||
#else
|
#else
|
||||||
#define DEBUG_LOG(msg, args...)
|
#define DEBUG_LOG(msg, args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* 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"
|
||||||
|
|
||||||
|
#include <execinfo.h>
|
||||||
|
|
||||||
|
pthread_t SERVER_THREAD;
|
||||||
|
pthread_t APPKIT_THREAD;
|
||||||
|
|
||||||
|
static 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
void threadAssert(pthread_t tid) {
|
||||||
|
if(pthread_equal(pthread_self(), tid))
|
||||||
|
return;
|
||||||
|
|
||||||
|
/* NOOOO! */
|
||||||
|
ErrorF("Thread Assertion Failed: self=%s, expected=%s\n",
|
||||||
|
threadSafetyID(pthread_self()), threadSafetyID(tid));
|
||||||
|
spewCallStack();
|
||||||
|
}
|
|
@ -0,0 +1,43 @@
|
||||||
|
/*
|
||||||
|
* 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_
|
||||||
|
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
|
extern pthread_t SERVER_THREAD;
|
||||||
|
extern pthread_t APPKIT_THREAD;
|
||||||
|
|
||||||
|
#define threadSafetyID(tid) (pthread_equal((tid), SERVER_THREAD) ? "X Server Thread" : "Appkit Thread")
|
||||||
|
|
||||||
|
/* Print message to ErrorF if we're in the wrong thread */
|
||||||
|
void threadAssert(pthread_t tid);
|
||||||
|
|
||||||
|
#define TA_SERVER() threadAssert(SERVER_THREAD)
|
||||||
|
#define TA_APPKIT() threadAssert(APPKIT_THREAD)
|
||||||
|
|
||||||
|
#endif _XQ_THREAD_SAFETY_H_
|
Loading…
Reference in New Issue