diff --git a/src/core/log.c b/src/core/log.c index b85c6555c33..de18b7c04b4 100644 --- a/src/core/log.c +++ b/src/core/log.c @@ -50,12 +50,6 @@ _Atomic #endif /* ATOMIC_OPERATIONS_SUPPORTED */ uintptr_t Core_log_function = 0; -/* the logging function's context */ -#ifdef ATOMIC_OPERATIONS_SUPPORTED -_Atomic -#endif /* ATOMIC_OPERATIONS_SUPPORTED */ -void *Core_log_function_context; - /* threshold levels */ enum core_log_level Core_log_threshold[] = { CORE_LOG_THRESHOLD_DEFAULT, @@ -78,7 +72,7 @@ core_log_init() /* enable the default logging function */ core_log_default_init(); while (EAGAIN == - core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL)) + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION)) ; } @@ -94,7 +88,6 @@ core_log_fini() * logging function. */ Core_log_function = 0; - Core_log_function_context = NULL; /* cleanup the default logging function */ core_log_default_fini(); @@ -117,7 +110,7 @@ core_log_lib_info(void) * a user-provided function pointer or to the default logging function. */ int -core_log_set_function(core_log_function *log_function, void *context) +core_log_set_function(core_log_function *log_function) { if (log_function == CORE_LOG_USE_DEFAULT_FUNCTION) @@ -126,25 +119,15 @@ core_log_set_function(core_log_function *log_function, void *context) #ifdef ATOMIC_OPERATIONS_SUPPORTED atomic_store_explicit(&Core_log_function, (uintptr_t)log_function, __ATOMIC_SEQ_CST); - atomic_store_explicit(&Core_log_function_context, context, - __ATOMIC_SEQ_CST); return 0; #else uintptr_t core_log_function_old = Core_log_function; - void *context_old = Core_log_function_context; - if (!__sync_bool_compare_and_swap(&Core_log_function, - core_log_function_old, (uintptr_t)log_function)) - return EAGAIN; - if (__sync_bool_compare_and_swap(&Core_log_function_context, - context_old, context)) { + if (__sync_bool_compare_and_swap(&Core_log_function, + core_log_function_old, (uintptr_t)log_function)) { core_log_lib_info(); return 0; } - - (void) __sync_bool_compare_and_swap(&Core_log_function, - (uintptr_t)log_function, core_log_function_old); return EAGAIN; - #endif /* ATOMIC_OPERATIONS_SUPPORTED */ } @@ -226,8 +209,8 @@ core_log_va(char *buf, size_t buf_len, enum core_log_level level, if (0 == Core_log_function) goto end; - ((core_log_function *)Core_log_function)(Core_log_function_context, - level, file_name, line_no, function_name, buf); + ((core_log_function *)Core_log_function)(level, file_name, line_no, + function_name, buf); end: if (errnum != NO_ERRNO) diff --git a/src/core/log_default.c b/src/core/log_default.c index b761a85a49a..563844af97d 100644 --- a/src/core/log_default.c +++ b/src/core/log_default.c @@ -98,12 +98,9 @@ get_timestamp_prefix(char *buf, size_t buf_size) * - file == NULL || (file != NULL && function != NULL) */ void -core_log_default_function(void *context, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, - const char *message) +core_log_default_function(enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, const char *message) { - SUPPRESS_UNUSED(context); - char file_info_buffer[256] = ""; const char *file_info = file_info_buffer; const char file_info_error[] = "[file info error]: "; diff --git a/src/core/log_default.h b/src/core/log_default.h index c7bdde7023b..7583dce6905 100644 --- a/src/core/log_default.h +++ b/src/core/log_default.h @@ -8,9 +8,8 @@ #ifndef CORE_LOG_DEFAULT_H #define CORE_LOG_DEFAULT_H -void core_log_default_function(void *context, enum core_log_level level, - const char *file_name, const int line_no, const char *function_name, - const char *message); +void core_log_default_function(enum core_log_level level, const char *file_name, + const int line_no, const char *function_name, const char *message); void core_log_default_init(void); diff --git a/src/core/log_internal.h b/src/core/log_internal.h index 2d03c1b3fa4..fb1a8bcf452 100644 --- a/src/core/log_internal.h +++ b/src/core/log_internal.h @@ -66,8 +66,6 @@ int core_log_get_threshold(enum core_log_threshold threshold, * the type used for defining logging functions */ typedef void core_log_function( - /* the context provided when setting the log function */ - void *context, /* the log level of the message */ enum core_log_level level, /* name of the source file where the message coming from */ @@ -81,7 +79,7 @@ typedef void core_log_function( #define CORE_LOG_USE_DEFAULT_FUNCTION (NULL) -int core_log_set_function(core_log_function *log_function, void *context); +int core_log_set_function(core_log_function *log_function); /* threshold levels */ extern diff --git a/src/core/out.c b/src/core/out.c index 9773b8667b3..f0bd95e4a08 100644 --- a/src/core/out.c +++ b/src/core/out.c @@ -52,11 +52,9 @@ static const int core_log_level_to_level[CORE_LOG_LEVEL_MAX] = { #define OUT_MAX_LEVEL 4 static void -out_legacy(void *context, enum core_log_level core_level, const char *file_name, +out_legacy(enum core_log_level core_level, const char *file_name, const int line_no, const char *function_name, const char *message) { - SUPPRESS_UNUSED(context); - int level = core_log_level_to_level[core_level]; out_log(file_name, line_no, function_name, level, "%s", message); } @@ -149,7 +147,7 @@ out_init(const char *log_prefix, const char *log_level_var, } if (log_level != NULL || log_file != NULL) { - ret = core_log_set_function(out_legacy, NULL); + ret = core_log_set_function(out_legacy); if (ret) { CORE_LOG_FATAL("Cannot set legacy log function"); } diff --git a/src/include/libpmemobj/log.h b/src/include/libpmemobj/log.h index 64f1d7855e7..43c0eaaecfe 100644 --- a/src/include/libpmemobj/log.h +++ b/src/include/libpmemobj/log.h @@ -153,8 +153,6 @@ int pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, * the type used for defining logging functions */ typedef void pmemobj_log_function( - /* the context provided when setting the log function */ - void *context, /* the log level of the message */ enum pmemobj_log_level level, /* name of the source file where the message coming from */ @@ -176,7 +174,6 @@ typedef void pmemobj_log_function( * SYNOPSIS * * typedef void pmemobj_log_function( - * void *context, * enum pmemobj_log_level level, * const char *file_name, * const int line_no, @@ -184,18 +181,13 @@ typedef void pmemobj_log_function( * const char *message_format, * ...); * - * int pmemobj_log_set_function(pmemobj_log_function *log_function, - * void *context); + * int pmemobj_log_set_function(pmemobj_log_function *log_function); * * DESCRIPTION * pmemobj_log_set_function() allows choosing the function which will get all * the generated logging messages. The log_function can be either * PMEMOBJ_LOG_USE_DEFAULT_FUNCTION which will use the default logging function * (built into the library) or a pointer to a user-defined function. - * The context allows to pass an additional value which will be passed along - * with all the logging messages to the logging function. When the provided - * log_function is PMEMOBJ_LOG_USE_DEFAULT_FUNCTION the provided context is - * ignored. * * Parameters of a user-defined log function are as follow: * - level - the log level of the message @@ -228,7 +220,7 @@ typedef void pmemobj_log_function( * SEE ALSO * pmemobj_log_get_threshold(3), pmemobj_log_set_threshold(3). */ -int pmemobj_log_set_function(pmemobj_log_function *log_function, void *context); +int pmemobj_log_set_function(pmemobj_log_function *log_function); #ifdef __cplusplus } diff --git a/src/libpmemobj/obj_log.c b/src/libpmemobj/obj_log.c index 3984e9e5d5e..aad0ad0f11a 100644 --- a/src/libpmemobj/obj_log.c +++ b/src/libpmemobj/obj_log.c @@ -38,12 +38,8 @@ pmemobj_log_get_threshold(enum pmemobj_log_threshold threshold, * a user-provided function pointer or to the default logging function. */ int -pmemobj_log_set_function(pmemobj_log_function *log_function, void *context) +pmemobj_log_set_function(pmemobj_log_function *log_function) { - if (log_function == PMEMOBJ_LOG_USE_DEFAULT_FUNCTION) - context = NULL; - - int ret = core_log_set_function((core_log_function *)log_function, - context); + int ret = core_log_set_function((core_log_function *)log_function); return core_log_error_translate(ret); } diff --git a/src/test/core_log/core_log.c b/src/test/core_log/core_log.c index 3263668ca40..75aa59891f6 100644 --- a/src/test/core_log/core_log.c +++ b/src/test/core_log/core_log.c @@ -216,7 +216,7 @@ int main(int argc, char *argv[]) { START(argc, argv, "core_log"); - core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION); openlog(NULL, LOG_NDELAY, LOG_USER); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); closelog(); diff --git a/src/test/core_log_default_function/core_log_default_function.c b/src/test/core_log_default_function/core_log_default_function.c index b685b4be806..01f9ba42b0f 100644 --- a/src/test/core_log_default_function/core_log_default_function.c +++ b/src/test/core_log_default_function/core_log_default_function.c @@ -190,7 +190,7 @@ test_default_function(const struct test_case *tc, int argc, char *argv[]) for (enum core_log_level level = CORE_LOG_LEVEL_HARK; level < CORE_LOG_LEVEL_MAX; level++) { TEST_STEP_SETUP(level, FILE_NAME); - core_log_default_function(NULL, level, FILE_NAME_W_PATH, + core_log_default_function(level, FILE_NAME_W_PATH, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); if (level == CORE_LOG_LEVEL_HARK || level > treshold) TEST_STEP_CHECK(1, 0); @@ -211,7 +211,7 @@ test_default_function_bad_file_name(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_INFO_ERROR); Snprintf.ret = -1; Common.exp_file_info = FILE_INFO_ERROR; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME_W_PATH, + core_log_default_function(CORE_LOG_LEVEL_DEBUG, FILE_NAME_W_PATH, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); @@ -227,7 +227,7 @@ test_default_function_short_file_name(const struct test_case *tc, int argc, TEST_SETUP(); TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_NAME); Strchr_ret = NULL; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME, + core_log_default_function(CORE_LOG_LEVEL_DEBUG, FILE_NAME, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); @@ -243,7 +243,7 @@ test_default_function_no_file_name(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, ""); FUNC_MOCK_RCOUNTER_SET(snprintf, 1); /* skip file_info snprintf() */ Common.exp_file_info = ""; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, NULL, + core_log_default_function(CORE_LOG_LEVEL_DEBUG, NULL, LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); @@ -259,8 +259,8 @@ test_default_function_no_function_name(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, ""); FUNC_MOCK_RCOUNTER_SET(snprintf, 1); /* skip file_info snprintf() */ Common.exp_file_info = ""; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, NULL, - LINE_NO, NULL, MESSAGE_MOCK); + core_log_default_function(CORE_LOG_LEVEL_DEBUG, NULL, LINE_NO, NULL, + MESSAGE_MOCK); TEST_STEP_CHECK(2, 1); return NO_ARGS_CONSUMED; @@ -275,8 +275,8 @@ test_default_function_bad_timestamp(const struct test_case *tc, int argc, TEST_STEP_SETUP(CORE_LOG_LEVEL_DEBUG, FILE_NAME); Os_clock_gettime_force_error = true; /* fail the file_info snprintf() */ Fprintf.exp_times_stamp = "[time error] "; - core_log_default_function(NULL, CORE_LOG_LEVEL_DEBUG, FILE_NAME, - LINE_NO, FUNCTION_NAME, MESSAGE_MOCK); + core_log_default_function(CORE_LOG_LEVEL_DEBUG, FILE_NAME, LINE_NO, + FUNCTION_NAME, MESSAGE_MOCK); TEST_STEP_CHECK(1, 1); return NO_ARGS_CONSUMED; diff --git a/src/test/core_log_internal/core_log_internal.c b/src/test/core_log_internal/core_log_internal.c index 6fd1af8d5a4..637cce50518 100644 --- a/src/test/core_log_internal/core_log_internal.c +++ b/src/test/core_log_internal/core_log_internal.c @@ -252,7 +252,7 @@ int main(int argc, char *argv[]) { core_log_get_threshold(CORE_LOG_THRESHOLD, &Core_log_default_threshold); - core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION, NULL); + core_log_set_function(CORE_LOG_USE_DEFAULT_FUNCTION); START(argc, argv, "core_log_internal"); TEST_CASE_PROCESS(argc, argv, test_cases, NTESTS); diff --git a/src/test/unittest/unittest.h b/src/test/unittest/unittest.h index a01a791e61f..c13422871ee 100644 --- a/src/test/unittest/unittest.h +++ b/src/test/unittest/unittest.h @@ -122,19 +122,19 @@ void ut_err(const char *file, int line, const char *func, __attribute__((format(printf, 4, 5))); void -ut_log_function(void *context, enum core_log_level level, const char *file_name, +ut_log_function(enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message); #ifdef USE_LOG_PMEMCORE -#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function, NULL) +#define LOG_SET_PMEMCORE_FUNC core_log_set_function(ut_log_function) #else #define LOG_SET_PMEMCORE_FUNC #endif #ifdef USE_LOG_PMEMOBJ #define LOG_SET_PMEMOBJ_FUNC \ - pmemobj_log_set_function((pmemobj_log_function *)ut_log_function, NULL) + pmemobj_log_set_function((pmemobj_log_function *)ut_log_function) #else #define LOG_SET_PMEMOBJ_FUNC #endif diff --git a/src/test/unittest/ut_log.c b/src/test/unittest/ut_log.c index a3773e00cde..8c03185fbbe 100644 --- a/src/test/unittest/ut_log.c +++ b/src/test/unittest/ut_log.c @@ -20,7 +20,7 @@ static const int core_log_level_to_out_level[] = { }; void -ut_log_function(void *context, enum core_log_level level, const char *file_name, +ut_log_function(enum core_log_level level, const char *file_name, const int line_no, const char *function_name, const char *message) { out_log(file_name, line_no, function_name,