XQuartz: A little more debugging output from threadSafety
(cherry picked from commit f6fbdbf838
)
This commit is contained in:
parent
0d61f6fca1
commit
55f80d7545
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#ifndef _XQ_THREAD_SAFETY_H_
|
||||
#define _XQ_THREAD_SAFETY_H_
|
||||
|
||||
#define DEBUG_THREADS 1
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
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_
|
||||
|
|
Loading…
Reference in New Issue
Block a user