summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2011-02-16 21:25:47 (GMT)
committerChristian Pointner <equinox@helsinki.at>2011-02-16 21:25:47 (GMT)
commitec6b037cd20e09766279689755df745e3da756ce (patch)
treedd328e662eb6c64606a77bb4a23156e11de79179 /src
parent95a985311dd1a1019762375e9013d018eb6e18bb (diff)
better locking für logging
Diffstat (limited to 'src')
-rw-r--r--src/log.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/log.c b/src/log.c
index 353fa06..ed13f74 100644
--- a/src/log.c
+++ b/src/log.c
@@ -152,7 +152,6 @@ 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)
@@ -160,7 +159,6 @@ 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)
@@ -189,8 +187,9 @@ void log_init()
void log_close()
{
- pthread_mutex_destroy(&(stdlog.log_mutex_));
+ pthread_mutex_lock(&(stdlog.log_mutex_));
log_targets_clear(&stdlog.targets_);
+ pthread_mutex_unlock(&(stdlog.log_mutex_));
}
void update_max_prio()
@@ -209,8 +208,10 @@ int log_add_target(const char* conf)
if(!conf)
return -1;
+ pthread_mutex_lock(&(stdlog.log_mutex_));
int ret = log_targets_add(&stdlog.targets_, conf);
if(!ret) update_max_prio();
+ pthread_mutex_unlock(&(stdlog.log_mutex_));
return ret;
}
@@ -226,7 +227,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_));
log_targets_log(&stdlog.targets_, prio, msg);
+ pthread_mutex_unlock(&(stdlog.log_mutex_));
}
void log_print_hex_dump(log_prio_t prio, const uint8_t* buf, uint32_t len)
@@ -253,5 +256,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_));
log_targets_log(&stdlog.targets_, prio, msg);
+ pthread_mutex_unlock(&(stdlog.log_mutex_));
}