From 62b1e20bb57ef059dee7e9bfb8ea8cc19967a5f7 Mon Sep 17 00:00:00 2001 From: Christian Thaeter Date: Fri, 18 Dec 2009 01:30:49 +0100 Subject: [PATCH] Factor log-locking out to the _LOG macro. the logging-log needs to protect the ++nobug_counter too. Unfortunally the postlogging callback must be moved to the macros too now. At least its more correct this way, maybe this needs some more refactoring in future to put this back into the logging function. --- src/nobug.c | 11 ----------- src/nobug.h | 23 +++++++++++++++++------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/nobug.c b/src/nobug.c index 546c4f9..e409f8f 100644 --- a/src/nobug.c +++ b/src/nobug.c @@ -145,10 +145,6 @@ nobug_destroy (void) void nobug_log (struct nobug_flag* flag, int lvl, const char* fmt, ...) { -#if NOBUG_USE_PTHREAD - pthread_mutex_lock (&nobug_logging_mutex); -#endif - char * log = nobug_ringbuffer_pos (flag->ringbuffer_target); va_list ap; va_start (ap, fmt); @@ -193,13 +189,6 @@ NOBUG_IF(NOBUG_USE_XXXX_TARGET ... NOBUG_RESOURCE_UNLOCK; } #endif - -#if NOBUG_USE_PTHREAD - pthread_mutex_unlock (&nobug_logging_mutex); -#endif - - if (nobug_postlogging_callback) - nobug_postlogging_callback (flag, lvl, NULL, nobug_callback_data); } diff --git a/src/nobug.h b/src/nobug.h index 317348a..781ef35 100644 --- a/src/nobug.h +++ b/src/nobug.h @@ -591,14 +591,19 @@ NOBUG_IF_NOT_RELEASE( */ #define NOBUG_LOG_(flag, lvl, location, what, ...) \ NOBUG_WHEN (lvl <= NOBUG_LOG_BASELIMIT && lvl <= (flag)->limits[NOBUG_TARGET_RINGBUFFER], \ - nobug_log (flag, lvl, \ - "%.10llu: %s: %s:%d:"NOBUG_THREAD_ID_FMT(" ",":")" %s: " \ - NOBUG_HEAD(__VA_ARGS__), ++nobug_counter, what, \ - NOBUG_LOCATION_FILE location, \ - NOBUG_LOCATION_LINE location NOBUG_THREAD_ID_COMMA, \ - NOBUG_LOCATION_FUNC location NOBUG_TAIL(__VA_ARGS__)) \ + NOBUG_LOGGING_LOCK; \ + nobug_log (flag, lvl, \ + "%.10llu: %s: %s:%d:"NOBUG_THREAD_ID_FMT(" ",":")" %s: " \ + NOBUG_HEAD(__VA_ARGS__), ++nobug_counter, what, \ + NOBUG_LOCATION_FILE location, \ + NOBUG_LOCATION_LINE location NOBUG_THREAD_ID_COMMA, \ + NOBUG_LOCATION_FUNC location NOBUG_TAIL(__VA_ARGS__)); \ + NOBUG_LOGGING_UNLOCK; \ + if (nobug_postlogging_callback) \ + nobug_postlogging_callback (flag, lvl, NULL, nobug_callback_data) \ ) + #define NOBUG_LVL(lvl) NOBUG_LVL_##lvl #define NOBUG_LVL_0 "EMERG" #define NOBUG_LVL_1 "ALERT" @@ -2133,9 +2138,13 @@ nobug_thread_data (void); /* resource registry */ + #if NOBUG_USE_PTHREAD #define NOBUG_RESOURCE_LOCK pthread_mutex_lock (&nobug_resource_mutex) #define NOBUG_RESOURCE_UNLOCK pthread_mutex_unlock (&nobug_resource_mutex) +#define NOBUG_LOGGING_LOCK pthread_mutex_lock (&nobug_logging_mutex) +#define NOBUG_LOGGING_UNLOCK pthread_mutex_unlock (&nobug_logging_mutex) + /* Note: errors are all fatal, we dont unlock the mutex when returning an error, this should be handled better in future but does not hurt @@ -2143,6 +2152,8 @@ nobug_thread_data (void); #else #define NOBUG_RESOURCE_LOCK #define NOBUG_RESOURCE_UNLOCK +#define NOBUG_LOGGING_LOCK +#define NOBUG_LOGGING_UNLOCK #endif enum nobug_resource_state -- 2.11.4.GIT