diff options
Diffstat (limited to 'src/log.c')
-rw-r--r-- | src/log.c | 22 |
1 files changed, 12 insertions, 10 deletions
@@ -32,7 +32,8 @@ #include <stdarg.h> #include <stdlib.h> #include <stdio.h> -#include <pthread.h> + +#include <glib.h> #define SYSLOG_NAMES #include <syslog.h> @@ -182,14 +183,15 @@ void log_init() { stdlog.max_prio_ = 0; stdlog.targets_.first_ = NULL; - pthread_mutex_init(&(stdlog.log_mutex_), NULL); + g_thread_init(NULL); + stdlog.log_mutex_ = g_mutex_new(); } void log_close() { - pthread_mutex_lock(&(stdlog.log_mutex_)); + g_mutex_lock(stdlog.log_mutex_); log_targets_clear(&stdlog.targets_); - pthread_mutex_unlock(&(stdlog.log_mutex_)); + g_mutex_unlock(stdlog.log_mutex_); } void update_max_prio() @@ -208,10 +210,10 @@ int log_add_target(const char* conf) if(!conf) return -1; - pthread_mutex_lock(&(stdlog.log_mutex_)); + g_mutex_lock(stdlog.log_mutex_); int ret = log_targets_add(&stdlog.targets_, conf); if(!ret) update_max_prio(); - pthread_mutex_unlock(&(stdlog.log_mutex_)); + g_mutex_unlock(stdlog.log_mutex_); return ret; } @@ -227,9 +229,9 @@ void log_printf(log_prio_t prio, const char* fmt, ...) vsnprintf(msg, MSG_LENGTH_MAX, fmt, args); va_end(args); - pthread_mutex_lock(&(stdlog.log_mutex_)); + g_mutex_lock(stdlog.log_mutex_); log_targets_log(&stdlog.targets_, prio, msg); - pthread_mutex_unlock(&(stdlog.log_mutex_)); + g_mutex_unlock(stdlog.log_mutex_); } void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len) @@ -256,7 +258,7 @@ void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len) ptr+=3; } } - pthread_mutex_lock(&(stdlog.log_mutex_)); + g_mutex_lock(stdlog.log_mutex_); log_targets_log(&stdlog.targets_, prio, msg); - pthread_mutex_unlock(&(stdlog.log_mutex_)); + g_mutex_unlock(stdlog.log_mutex_); } |