summaryrefslogtreecommitdiffstats
path: root/src/server/locks.h
diff options
context:
space:
mode:
authorsr2013-07-16 21:20:07 +0200
committersr2013-07-16 21:20:07 +0200
commitc31b8d90a4e4809ada5b60fcdcc93b6ecf9326e4 (patch)
treecc5d5901ddb7bc7ba9c2c2beeaee3154c8a3b0f7 /src/server/locks.h
parentFix more bugs, remove debug messages (diff)
downloaddnbd3-c31b8d90a4e4809ada5b60fcdcc93b6ecf9326e4.tar.gz
dnbd3-c31b8d90a4e4809ada5b60fcdcc93b6ecf9326e4.tar.xz
dnbd3-c31b8d90a4e4809ada5b60fcdcc93b6ecf9326e4.zip
Add debug-lock functions that will helpt to spot deadlocks etc. while developing
Diffstat (limited to 'src/server/locks.h')
-rw-r--r--src/server/locks.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server/locks.h b/src/server/locks.h
new file mode 100644
index 0000000..9a0a024
--- /dev/null
+++ b/src/server/locks.h
@@ -0,0 +1,30 @@
+#ifndef _LOCKS_H_
+#define _LOCKS_H_
+
+#ifdef _DEBUG
+
+#include <pthread.h>
+
+#define spin_init( lock, type ) debug_spin_init( #lock, __FILE__, __LINE__, lock, type)
+#define spin_lock( lock ) debug_spin_lock( #lock, __FILE__, __LINE__, lock)
+#define spin_unlock( lock ) debug_spin_unlock( #lock, __FILE__, __LINE__, lock)
+#define spin_destroy( lock ) debug_spin_destroy( #lock, __FILE__, __LINE__, lock)
+
+int debug_spin_init(const char *name, const char *file, int line, pthread_spinlock_t *lock, int shared);
+int debug_spin_lock(const char *name, const char *file, int line, pthread_spinlock_t *lock);
+int debug_spin_unlock(const char *name, const char *file, int line, pthread_spinlock_t *lock);
+int debug_spin_destory(const char *name, const char *file, int line, pthread_spinlock_t *lock);
+
+void debug_dump_lock_stats();
+void *debug_thread_watchdog(void *something);
+
+#else
+
+#define spin_init( lock, type ) pthread_spin_init(lock, type)
+#define spin_lock( lock ) pthread_spin_lock(lock)
+#define spin_unlock( lock ) pthread_spin_unlock(lock)
+#define spin_destroy( lock ) pthread_spin_destroy(lock)
+
+#endif
+
+#endif /* LOCKS_H_ */