diff options
author | Stef Walter <stefw@collabora.co.uk> | 2011-10-17 14:51:31 +0200 |
---|---|---|
committer | Stef Walter <stefw@collabora.co.uk> | 2011-10-17 15:32:41 +0200 |
commit | db92b76e3acb11e330309ebce071ec2e61400a71 (patch) | |
tree | cb11139880974ef8db53dd83a70de8f32d94cc09 /p11-kit/debug.c | |
parent | b1d9fd5f88ade222fbd2206c7e11c5514c8b5634 (diff) |
Initial port to win32
* Tests do not all yet pass, at least not on wine
* Added abstraction of some non-portable functions in compat.h/c
* Build with an argument like this for win32 support:
./autogen.sh --host=i586-mingw32msvc
* This win32 port needs more work from interested parties
Diffstat (limited to 'p11-kit/debug.c')
-rw-r--r-- | p11-kit/debug.c | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/p11-kit/debug.c b/p11-kit/debug.c index e4b39f0..5766dae 100644 --- a/p11-kit/debug.c +++ b/p11-kit/debug.c @@ -36,9 +36,10 @@ #include "config.h" +#include "compat.h" #include "debug.h" -#include <pthread.h> +#include <assert.h> #include <stdio.h> #include <stdarg.h> #include <stdlib.h> @@ -58,10 +59,11 @@ static struct DebugKey debug_keys[] = { { 0, } }; -pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER; +static int debug_inited = 0; +static mutex_t debug_mutex; /* global variable exported in debug.h */ -int debug_current_flags = ~0; +int debug_current_flags; static int parse_environ_flags (void) @@ -109,22 +111,21 @@ parse_environ_flags (void) } void +debug_init (void) +{ + debug_current_flags = parse_environ_flags (); + mutex_init (&debug_mutex); + debug_inited = 1; +} + +void debug_message (int flag, const char *format, ...) { - static int initialized_flags = 0; char buffer[512]; va_list args; - pthread_mutex_lock (&debug_mutex); - - /* - * This is not thread-safe, but it's not really the end of the - * world if it happens more than once. - */ - if (!initialized_flags) { - initialized_flags = 1; - debug_current_flags = parse_environ_flags (); - } + assert (debug_inited); + mutex_lock (&debug_mutex); if (flag & debug_current_flags) { va_start (args, format); @@ -134,5 +135,5 @@ debug_message (int flag, const char *format, ...) fprintf (stderr, "(p11-kit:%d) %s\n", getpid(), buffer); } - pthread_mutex_unlock (&debug_mutex); + mutex_unlock (&debug_mutex); } |