include/common.h
branchpyrit
changeset 52 a6413a3d741d
parent 48 a4913301c626
child 78 9569e9f35374
equal deleted inserted replaced
51:89fec8668768 52:a6413a3d741d
    28 #define COMMON_H
    28 #define COMMON_H
    29 
    29 
    30 #include <stdio.h>
    30 #include <stdio.h>
    31 #include <stdarg.h>
    31 #include <stdarg.h>
    32 #include <float.h>
    32 #include <float.h>
       
    33 #include <pthread.h>
    33 
    34 
    34 #ifdef PYRIT_DOUBLE
    35 #ifdef PYRIT_DOUBLE
    35 # define Float double
    36 # define Float double
    36 # define Eps DBL_EPSILON
    37 # define Eps DBL_EPSILON
    37 # define Inf DBL_MAX
    38 # define Inf DBL_MAX
    44 /* verbosity level:
    45 /* verbosity level:
    45 0: only errors (E)
    46 0: only errors (E)
    46 1: major status messages (*)
    47 1: major status messages (*)
    47 2: minor status, progress (-)
    48 2: minor status, progress (-)
    48 3: debug messages (D)
    49 3: debug messages (D)
    49 4: more debug
    50 4: thread debug
    50 default = 2
    51 default = 2
    51 */
    52 */
    52 extern int pyrit_verbosity;
    53 extern int pyrit_verbosity;
    53 
    54 
    54 inline void dbgmsg(const int vlevel, const char *format, ...)
    55 inline void dbgmsg(const int vlevel, const char *format, ...)
    55 {
    56 {
       
    57 	static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
    56 	if (pyrit_verbosity >= vlevel)
    58 	if (pyrit_verbosity >= vlevel)
    57 	{
    59 	{
       
    60 		if (pyrit_verbosity >= 4)
       
    61 			pthread_mutex_lock(&mutex);
       
    62 
    58 		va_list ap;
    63 		va_list ap;
    59 		va_start(ap, format);
    64 		va_start(ap, format);
    60 		vprintf(format, ap);
    65 		vprintf(format, ap);
    61 		va_end(ap);
    66 		va_end(ap);
    62 		fflush(stdout);
    67 		fflush(stdout);
       
    68 
       
    69 		if (pyrit_verbosity >= 4)
       
    70 			pthread_mutex_unlock(&mutex);
    63 	}
    71 	}
    64 }
    72 }
    65 
    73 
    66 template<typename Type> const Type &min3(const Type &a, const Type &b, const Type &c)
    74 template<typename Type> const Type &min3(const Type &a, const Type &b, const Type &c)
    67 {
    75 {