diff mbox

[1/4] linux-generic: debug: use global fn ptr for logging fn

Message ID 1421632584-26181-2-git-send-email-mike.holmes@linaro.org
State Superseded
Headers show

Commit Message

Mike Holmes Jan. 19, 2015, 1:56 a.m. UTC
To allow init_global to replace the default logging function without
the need to use weak symbols a global location is needed to hold the
current logging function pointer.

Signed-off-by: Mike Holmes <mike.holmes@linaro.org>
---
 platform/linux-generic/include/api/odp_debug.h      | 2 ++
 platform/linux-generic/include/odp_debug_internal.h | 7 ++++---
 platform/linux-generic/include/odp_internal.h       | 5 +++++
 platform/linux-generic/odp_init.c                   | 2 ++
 4 files changed, 13 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/platform/linux-generic/include/api/odp_debug.h b/platform/linux-generic/include/api/odp_debug.h
index a4ce1d9..4c32500 100644
--- a/platform/linux-generic/include/api/odp_debug.h
+++ b/platform/linux-generic/include/api/odp_debug.h
@@ -76,6 +76,8 @@  typedef enum odp_log_level {
 extern int odp_override_log(odp_log_level_e level, const char *fmt, ...);
 
 
+/** Replaceable logging function */
+typedef int (*odp_log_func_t)(odp_log_level_e level, const char *fmt, ...);
 
 /**
  * @}
diff --git a/platform/linux-generic/include/odp_debug_internal.h b/platform/linux-generic/include/odp_debug_internal.h
index f6180d1..0b64fca 100644
--- a/platform/linux-generic/include/odp_debug_internal.h
+++ b/platform/linux-generic/include/odp_debug_internal.h
@@ -20,6 +20,7 @@ 
 #include <stdlib.h>
 #include <stdarg.h>
 #include <odp_debug.h>
+#include <odp_internal.h>
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -60,7 +61,7 @@  extern "C" {
  * This macro is used to indicate when a given function is not implemented
  */
 #define ODP_UNIMPLEMENTED() \
-		odp_override_log(ODP_LOG_UNIMPLEMENTED, \
+		odp_global_data.log_fn(ODP_LOG_UNIMPLEMENTED, \
 			"%s:%d:The function %s() is not implemented\n", \
 			__FILE__, __LINE__, __func__)
 /**
@@ -92,7 +93,7 @@  extern "C" {
  * ODP LOG macro.
  */
 #define ODP_LOG(level, fmt, ...) \
-	odp_override_log(level, "%s:%d:%s():" fmt, __FILE__, \
+	odp_global_data.log_fn(level, "%s:%d:%s():" fmt, __FILE__, \
 	__LINE__, __func__, ##__VA_ARGS__)
 
 /**
@@ -100,7 +101,7 @@  extern "C" {
  * specifically for dumping internal data.
  */
 #define ODP_PRINT(fmt, ...) \
-	odp_override_log(ODP_LOG_PRINT, " " fmt, ##__VA_ARGS__)
+	odp_global_data.log_fn(ODP_LOG_PRINT, " " fmt, ##__VA_ARGS__)
 
 #ifdef __cplusplus
 }
diff --git a/platform/linux-generic/include/odp_internal.h b/platform/linux-generic/include/odp_internal.h
index 549d406..7401a30 100644
--- a/platform/linux-generic/include/odp_internal.h
+++ b/platform/linux-generic/include/odp_internal.h
@@ -18,6 +18,11 @@ 
 extern "C" {
 #endif
 
+#include <odp_debug.h>
+
+struct odp_global_data {
+	odp_log_func_t log_fn;
+} odp_global_data;
 
 int odp_system_info_init(void);
 
diff --git a/platform/linux-generic/odp_init.c b/platform/linux-generic/odp_init.c
index 4d0aa07..a9f003f 100644
--- a/platform/linux-generic/odp_init.c
+++ b/platform/linux-generic/odp_init.c
@@ -13,6 +13,8 @@ 
 int odp_init_global(odp_init_t *params  ODP_UNUSED,
 			odp_platform_init_t *platform_params ODP_UNUSED)
 {
+	odp_global_data.log_fn = odp_override_log;
+
 	odp_system_info_init();
 
 	if (odp_shm_init_global()) {