include/common.h
branchpyrit
changeset 52 a6413a3d741d
parent 48 a4913301c626
child 78 9569e9f35374
--- a/include/common.h	Fri Mar 28 21:47:32 2008 +0100
+++ b/include/common.h	Fri Mar 28 23:30:04 2008 +0100
@@ -30,6 +30,7 @@
 #include <stdio.h>
 #include <stdarg.h>
 #include <float.h>
+#include <pthread.h>
 
 #ifdef PYRIT_DOUBLE
 # define Float double
@@ -46,20 +47,27 @@
 1: major status messages (*)
 2: minor status, progress (-)
 3: debug messages (D)
-4: more debug
+4: thread debug
 default = 2
 */
 extern int pyrit_verbosity;
 
 inline void dbgmsg(const int vlevel, const char *format, ...)
 {
+	static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
 	if (pyrit_verbosity >= vlevel)
 	{
+		if (pyrit_verbosity >= 4)
+			pthread_mutex_lock(&mutex);
+
 		va_list ap;
 		va_start(ap, format);
 		vprintf(format, ap);
 		va_end(ap);
 		fflush(stdout);
+
+		if (pyrit_verbosity >= 4)
+			pthread_mutex_unlock(&mutex);
 	}
 }