summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Huddleston <jeremyhu@freedesktop.org>2008-04-17 14:21:31 -0700
committerJeremy Huddleston <jeremyhu@freedesktop.org>2008-04-17 15:24:33 -0700
commit55f80d754525398378de1ef28aa562bd29ee750f (patch)
tree7b56167c627a269ac75f5f808e4d6e5a39976756
parent0d61f6fca1efeb4f68488e323d1c0508b9b7a711 (diff)
XQuartz: A little more debugging output from threadSafety
(cherry picked from commit f6fbdbf838ab77c3a4635f0b2356b1bbb060ff5b)
-rw-r--r--hw/xquartz/threadSafety.c9
-rw-r--r--hw/xquartz/threadSafety.h11
2 files changed, 15 insertions, 5 deletions
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 <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_