summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-02-16 21:16:40 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-02-16 21:16:40 (GMT)
commit95a985311dd1a1019762375e9013d018eb6e18bb (patch)
tree88a77ff8f27d716423a8bf886e70e71af99d88b3 /src
parent1961ba11afb0e0a71bcce7fc264e3ea403049d82 (diff)
log_printf is thread safe now, however log_init and log_add_target isn't
Diffstat (limited to 'src')
-rw-r--r--src/log.c9
-rw-r--r--src/log.h3
-rw-r--r--src/rharchive.c4
3 files changed, 12 insertions, 4 deletions
diff --git a/src/log.c b/src/log.c
index e167c5c..353fa06 100644
--- a/src/log.c
+++ b/src/log.c
@@ -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)");
diff --git a/src/log.h b/src/log.h
index 30ae7df..aaf7a1a 100644
--- a/src/log.h
+++ b/src/log.h
@@ -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;