diff options
Diffstat (limited to 'debug.c')
-rw-r--r-- | debug.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -81,12 +81,38 @@ struct dbg_config_t { */ }; +#ifdef WITH_DBG_MUTEX + pthread_mutex_t localtime_mutex; +#endif + +struct tm *dbg_localtime(const time_t *timep, struct tm *result) +{ + struct tm *res = NULL; +#ifdef WITH_DBG_MUTEX + pthread_mutex_lock(&localtime_mutex); +#endif + + if(timep && result) { + memcpy(result,localtime(timep),sizeof(*result)); + res = result; + } + +#ifdef WITH_DBG_MUTEX + pthread_mutex_unlock(&localtime_mutex); +#endif + + return res; +} + + static void dbg_mutex_init() { #ifdef WITH_DBG_MUTEX if(dbg_config.flags & DBG_FLAG_USE_MUTEX) { pthread_mutex_init(&dbg_config.mutex, NULL); } + + pthread_mutex_init(&localtime_mutex, NULL); #endif } @@ -117,6 +143,8 @@ static void dbg_mutex_close() dbg_mutex_unlock(); pthread_mutex_destroy(&dbg_config.mutex); } + + pthread_mutex_destroy(&localtime_mutex); #endif } @@ -206,7 +234,7 @@ static int dbg_create_header(char *hdr, size_t size) { time_t rawtime = time(NULL); struct tm t; - localtime_r(&rawtime, &t); + dbg_localtime(&rawtime, &t); return snprintf(hdr, size, "%d-%02d-%02d %02d:%02d:%02d", |