diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 9 | ||||
-rw-r--r-- | src/log.h | 3 | ||||
-rw-r--r-- | src/rharchive.c | 4 |
3 files changed, 12 insertions, 4 deletions
@@ -32,6 +32,7 @@ #include <stdarg.h> #include <stdlib.h> #include <stdio.h> +#include <pthread.h> #define SYSLOG_NAMES #include <syslog.h> @@ -151,6 +152,7 @@ void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg) if(!targets) return; + pthread_mutex_lock(&(stdlog.log_mutex_)); log_target_t* tmp = targets->first_; while(tmp) { if(tmp->log != NULL && tmp->enabled_ && tmp->max_prio_ >= prio) @@ -158,6 +160,7 @@ void log_targets_log(log_targets_t* targets, log_prio_t prio, const char* msg) tmp = tmp->next_; } + pthread_mutex_unlock(&(stdlog.log_mutex_)); } void log_targets_clear(log_targets_t* targets) @@ -181,10 +184,12 @@ void log_init() { stdlog.max_prio_ = 0; stdlog.targets_.first_ = NULL; + pthread_mutex_init(&(stdlog.log_mutex_), NULL); } void log_close() { + pthread_mutex_destroy(&(stdlog.log_mutex_)); log_targets_clear(&stdlog.targets_); } @@ -214,7 +219,7 @@ void log_printf(log_prio_t prio, const char* fmt, ...) if(stdlog.max_prio_ < prio) return; - static char msg[MSG_LENGTH_MAX]; + char msg[MSG_LENGTH_MAX]; va_list args; va_start(args, fmt); @@ -229,7 +234,7 @@ void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len) if(stdlog.max_prio_ < prio) return; - static char msg[MSG_LENGTH_MAX]; + char msg[MSG_LENGTH_MAX]; if(!buf) { snprintf(msg, MSG_LENGTH_MAX, "(NULL)"); @@ -28,6 +28,8 @@ #ifndef RHARCHIVE_log_h_INCLUDED #define RHARCHIVE_log_h_INCLUDED +#include <pthread.h> + #define MSG_LENGTH_MAX 1024 enum log_prio_enum { ERROR = 1, WARNING = 2, NOTICE = 3, @@ -69,6 +71,7 @@ void log_targets_clear(log_targets_t* targets); struct log_struct { log_prio_t max_prio_; log_targets_t targets_; + pthread_mutex_t log_mutex_; }; typedef struct log_struct log_t; diff --git a/src/rharchive.c b/src/rharchive.c index a44a5d2..6ab1538 100644 --- a/src/rharchive.c +++ b/src/rharchive.c @@ -47,7 +47,7 @@ static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) switch (GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: { - log_printf(NOTICE, "End of stream"); // thread safety... + log_printf(NOTICE, "End of stream"); g_main_loop_quit (loop); break; } @@ -57,7 +57,7 @@ static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) gst_message_parse_error(msg, &error, &debug); g_free(debug); - log_printf(ERROR, "%s", error->message); // thread safety... + log_printf(ERROR, "%s", error->message); g_error_free(error); g_main_loop_quit(loop); break; |