diff --git a/hw/xquartz/threadSafety.c b/hw/xquartz/threadSafety.c index ff19863f0..c0ec1e4e6 100644 --- a/hw/xquartz/threadSafety.c +++ b/hw/xquartz/threadSafety.c @@ -36,7 +36,7 @@ pthread_t SERVER_THREAD; pthread_t APPKIT_THREAD; -static void spewCallStack(void) { +static inline void spewCallStack(void) { void* callstack[128]; int i, frames = backtrace(callstack, 128); char** strs = backtrace_symbols(callstack, frames); @@ -48,12 +48,13 @@ static void spewCallStack(void) { free(strs); } -void threadAssert(pthread_t tid) { +void _threadAssert(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", - threadSafetyID(pthread_self()), threadSafetyID(tid)); + ErrorF("Thread Assertion Failed: self=%s, expected=%s\n%s:%s:%d\n", + threadSafetyID(pthread_self()), threadSafetyID(tid), + file, fun, line); spewCallStack(); } diff --git a/hw/xquartz/threadSafety.h b/hw/xquartz/threadSafety.h index 050469e4b..da3b5992e 100644 --- a/hw/xquartz/threadSafety.h +++ b/hw/xquartz/threadSafety.h @@ -27,6 +27,8 @@ #ifndef _XQ_THREAD_SAFETY_H_ #define _XQ_THREAD_SAFETY_H_ +#define DEBUG_THREADS 1 + #include extern pthread_t SERVER_THREAD; @@ -35,9 +37,16 @@ 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); +void _threadAssert(pthread_t tid, const char *file, const char *fun, int line); +#define threadAssert(tid) _threadAssert(tid, __FILE__, __FUNCTION__, __LINE__) + +#ifdef DEBUG_THREADS #define TA_SERVER() threadAssert(SERVER_THREAD) #define TA_APPKIT() threadAssert(APPKIT_THREAD) +#else +#define TA_SERVER() +#define TA_APPKIT() +#endif #endif _XQ_THREAD_SAFETY_H_