summaryrefslogtreecommitdiff
path: root/src/wrapper/verbose.h
blob: 00f72a09f08cb40c65b76135fe64463178aabb06 (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
#pragma once

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

static void
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