Made threadsafe
This commit is contained in:
parent
29db56723c
commit
ae389dfe86
|
@ -4,6 +4,7 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
|
#include <pthread.h>
|
||||||
|
|
||||||
#include "gm-debug.h"
|
#include "gm-debug.h"
|
||||||
|
|
||||||
|
@ -20,6 +21,7 @@ static LevelMap level_mapping[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static gint debug_level = DEBUG_ALWAYS;
|
static gint debug_level = DEBUG_ALWAYS;
|
||||||
|
static pthread_mutex_t mutex_debug = PTHREAD_MUTEX_INITIALIZER;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gm_debug_msg_real(FILE *f, struct tm *timet, gchar *line, va_list args) {
|
gm_debug_msg_real(FILE *f, struct tm *timet, gchar *line, va_list args) {
|
||||||
|
@ -34,7 +36,9 @@ gm_debug_msg(gint level, gchar *line, ...) {
|
||||||
struct tm *timet;
|
struct tm *timet;
|
||||||
time_t timer;
|
time_t timer;
|
||||||
va_list args;
|
va_list args;
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mutex_debug);
|
||||||
|
|
||||||
if ((debug_level | level) == debug_level) {
|
if ((debug_level | level) == debug_level) {
|
||||||
va_start(args, line);
|
va_start(args, line);
|
||||||
timer = time(0);
|
timer = time(0);
|
||||||
|
@ -50,6 +54,8 @@ gm_debug_msg(gint level, gchar *line, ...) {
|
||||||
|
|
||||||
va_end(args);
|
va_end(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_debug);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -64,6 +70,8 @@ gm_debug_set_level(gchar *level) {
|
||||||
|
|
||||||
levels = g_strsplit(level, ",", -1);
|
levels = g_strsplit(level, ",", -1);
|
||||||
|
|
||||||
|
pthread_mutex_lock(&mutex_debug);
|
||||||
|
|
||||||
for (iter = levels; *iter; ++iter) {
|
for (iter = levels; *iter; ++iter) {
|
||||||
for (map = level_mapping; map->name; ++map) {
|
for (map = level_mapping; map->name; ++map) {
|
||||||
if (strcasecmp(map->name, *iter) == 0) {
|
if (strcasecmp(map->name, *iter) == 0) {
|
||||||
|
@ -73,5 +81,6 @@ gm_debug_set_level(gchar *level) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&mutex_debug);
|
||||||
g_strfreev(levels);
|
g_strfreev(levels);
|
||||||
}
|
}
|
||||||
|
|
Reference in New Issue