summaryrefslogtreecommitdiffstats
path: root/src/server/locks.h
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-16 19:24:17 +0200
committerSimon Rettberg2014-06-16 19:24:17 +0200
commit49f9218d330f5842fe24bce79267bd2c5b239df3 (patch)
tree74e7b49e9c058145069ac4e2aa6de5d9f2cac3ce /src/server/locks.h
parent[CLIENT] Debug argument handling in daemon mode (diff)
downloaddnbd3-49f9218d330f5842fe24bce79267bd2c5b239df3.tar.gz
dnbd3-49f9218d330f5842fe24bce79267bd2c5b239df3.tar.xz
dnbd3-49f9218d330f5842fe24bce79267bd2c5b239df3.zip
Improve uplink handling, add code to debug thread creation/destruction, change stupid convention of freeDiskSpace returning 0 on error, which is ambiguous to the disk simply being full...
Diffstat (limited to 'src/server/locks.h')
-rw-r--r--src/server/locks.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/server/locks.h b/src/server/locks.h
index 43a3943..ab355c9 100644
--- a/src/server/locks.h
+++ b/src/server/locks.h
@@ -4,6 +4,9 @@
#ifdef _DEBUG
#include <pthread.h>
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.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)
@@ -19,6 +22,7 @@ int debug_spin_destroy(const char *name, const char *file, int line, pthread_spi
void debug_dump_lock_stats();
+
#else
#define spin_init( lock, type ) pthread_spin_init(lock, type)
@@ -29,6 +33,52 @@ void debug_dump_lock_stats();
#endif
+#ifdef DEBUG_THREADS
+
+extern int debugThreadCount;
+#define thread_create(thread,attr,routine,arg) (printf("[THREAD CREATE] %d @ %s:%d\n", debugThreadCount, __FILE__, (int)__LINE__), debug_thread_create(thread, attr, routine, arg))
+static inline pthread_t debug_thread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg)
+{
+ int i;
+ if (attr == NULL || pthread_attr_getdetachstate(attr, &i) != 0 || i == PTHREAD_CREATE_JOINABLE) {
+ ++debugThreadCount;
+ }
+ return pthread_create( thread, attr, start_routine, arg );
+}
+
+#define thread_detach(thread) (printf("[THREAD DETACH] %d @ %s:%d\n", debugThreadCount, __FILE__, __LINE__), debug_thread_detach(thread))
+static inline int debug_thread_detach(pthread_t thread)
+{
+ const int ret = pthread_detach(thread);
+ if (ret == 0) {
+ --debugThreadCount;
+ } else {
+ printf("[THREAD DETACH] Tried to detach invalid thread (error %d)\n", (int)errno);
+ exit(1);
+ }
+ return ret;
+}
+#define thread_join(thread,value) (printf("[THREAD JOIN] %d @ %s:%d\n", debugThreadCount, __FILE__, __LINE__), debug_thread_join(thread,value))
+static inline int debug_thread_join(pthread_t thread, void **value_ptr)
+{
+ const int ret = pthread_join(thread, value_ptr);
+ if (ret == 0) {
+ --debugThreadCount;
+ } else {
+ printf("[THREAD JOIN] Tried to join invalid thread (error %d)\n", (int)errno);
+ exit(1);
+ }
+ return ret;
+}
+
+#else
+
+#define thread_create(thread,attr,routine,param) pthread_create( thread, attr, routine, param )
+#define thread_detach(thread) pthread_detach( thread )
+#define thread_join(thread,value) pthread_join( thread, value )
+
+#endif
+
void debug_locks_start_watchdog();
void debug_locks_stop_watchdog();