diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/log.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -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_)); } |