summaryrefslogtreecommitdiff
path: root/src/wrapper/verbose.h
blob: 3f547955ee269f54df60eaad86190916bec253f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#pragma once

#include <stdio.h>
#include <stdarg.h>
#include <pthread.h>

#ifdef VERBOSE_FUNCTIONS
// Don't inline to get warnings from files that don't log at all
static void
#else
static inline void
#endif
verbose_log(const char *fmt, ...)
{
   static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
   pthread_mutex_lock(&mutex);
   fprintf(stderr"%lu: ", pthread_self());
   va_list ap;
   va_start(ap, fmt);
   vfprintf(stderr, fmt, ap);
   va_end(ap);
   fputc('\n'stderr);
   pthread_mutex_unlock(&mutex);
}

#ifdef VERBOSE_FUNCTIONS
#  define verbose verbose_log
#else
#  define verbose(...)
#endif