rcuja: Add debug output
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 18 May 2013 15:18:31 +0000 (17:18 +0200)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 18 May 2013 15:18:31 +0000 (17:18 +0200)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
rcuja/rcuja-internal.h

index 6b8da15a1a6131b249c3f70e3d3a45b3df99716d..96e9dabf6225d58ebb91e445c574c8a21ecc3551 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#define _GNU_SOURCE
 #include <pthread.h>
 #include <stdio.h>
 #include <inttypes.h>
+#include <unistd.h>
 #include <urcu/rculfhash.h>
 
 /*
@@ -161,14 +163,38 @@ int rcuja_delete_ht(struct cds_lfht *ht);
 
 //#define DEBUG
 
+#ifdef __linux__
+#include <syscall.h>
+#endif
+
+#if defined(_syscall0)
+_syscall0(pid_t, gettid)
+#elif defined(__NR_gettid)
+static inline pid_t gettid(void)
+{
+       return syscall(__NR_gettid);
+}
+#else
+#warning "use pid as tid"
+static inline pid_t gettid(void)
+{
+       return getpid();
+}
+#endif
+
 #ifdef DEBUG
-#define dbg_printf(fmt, args...)     printf("[debug rcuja] " fmt, ## args)
+#define dbg_printf(fmt, args...)                               \
+       fprintf(stderr, "[debug rcuja %lu %s()@%s:%u] " fmt,    \
+               (unsigned long) gettid(), __func__,             \
+               __FILE__, __LINE__, ## args)
 #else
 #define dbg_printf(fmt, args...)                               \
 do {                                                           \
        /* do nothing but check printf format */                \
        if (0)                                                  \
-               printf("[debug rcuja] " fmt, ## args);  \
+               fprintf(stderr, "[debug rcuja %lu %s()@%s:%u] " fmt, \
+                       (unsigned long) gettid(), __func__,     \
+                       __FILE__, __LINE__, ## args);           \
 } while (0)
 #endif
 
This page took 0.027129 seconds and 4 git commands to generate.