From 05193e78a2553c93a61da19a39e1276b1a509bac Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Mon, 17 Feb 2014 17:59:15 +0100 Subject: [PATCH] Use pthread_atfork to lock/unlock yaz_log system --- include/yaz/log.h | 3 --- src/log.c | 11 ++++++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/include/yaz/log.h b/include/yaz/log.h index 3d7bb67..57bad18 100644 --- a/include/yaz/log.h +++ b/include/yaz/log.h @@ -220,9 +220,6 @@ YAZ_EXPORT void log_event_end(void (*func)(int level, const char *msg, */ YAZ_EXPORT void yaz_log_xml_errors(const char *prefix, int log_level); -YAZ_EXPORT void yaz_log_lock(void); -YAZ_EXPORT void yaz_log_unlock(void); - YAZ_END_CDECL #endif diff --git a/src/log.c b/src/log.c index b407ad9..38ecac7 100644 --- a/src/log.c +++ b/src/log.c @@ -33,6 +33,9 @@ #include #include #include +#if YAZ_POSIX_THREADS +#include +#endif static int l_level = YLOG_DEFAULT_LEVEL; @@ -102,12 +105,12 @@ static unsigned int next_log_bit = YLOG_LAST_BIT<<1; /* first dynamic bit */ static YAZ_MUTEX log_mutex = 0; -void yaz_log_lock(void) +static void yaz_log_lock(void) { yaz_mutex_enter(log_mutex); } -void yaz_log_unlock(void) +static void yaz_log_unlock(void) { yaz_mutex_leave(log_mutex); } @@ -123,7 +126,9 @@ static void internal_log_init(void) if (log_mutex == 0) yaz_mutex_create(&log_mutex); - +#if YAZ_POSIX_THREADS + pthread_atfork(yaz_log_lock, yaz_log_unlock, yaz_log_unlock); +#endif env = getenv("YAZ_LOG"); if (env) l_level = yaz_log_mask_str_x(env, l_level); -- 1.7.10.4