Make log related global variables as local 83/239383/3
authorXuelian <xuelian.bai@samsung.com>
Fri, 17 Jul 2020 14:36:34 +0000 (22:36 +0800)
committerXuelian <xuelian.bai@samsung.com>
Tue, 11 Aug 2020 16:27:05 +0000 (00:27 +0800)
Make coregl_log_lvl, coregl_dlog_enable,coregl_log_initialized as
local.

Change-Id: I6020d3431d089246d3e51c4c90bbdfff5c0a5126
Signed-off-by: Xuelian Bai <xuelian.bai@samsung.com>
src/coregl.c
src/coregl.h
src/coregl_internal.h

index 80b51fd..b03d317 100644 (file)
@@ -20,6 +20,46 @@ static int          api_gl_version = COREGL_GLAPI_2;
 #include "headers/sym.h"
 #undef _COREGL_SYMBOL
 
+static unsigned int coregl_log_lvl;
+static unsigned int coregl_dlog_enable;
+static unsigned int coregl_log_initialized;
+
+unsigned int
+coregl_get_log_lvl()
+{
+    return coregl_log_lvl;
+}
+
+void
+coregl_set_log_lvl(unsigned int value)
+{
+     coregl_log_lvl = value;
+}
+
+unsigned int
+coregl_get_dlog_enable()
+{
+    return coregl_dlog_enable;
+}
+
+void
+coregl_set_dlog_enable(unsigned int value)
+{
+    coregl_dlog_enable = value;
+}
+
+unsigned int
+coregl_get_log_init()
+{
+    return coregl_log_initialized;
+}
+
+void
+coregl_set_log_init(unsigned int value)
+{
+    coregl_log_initialized = value;
+}
+
 const char *
 get_env_setting(const char *name)
 {
index 13fa585..f3bf637 100644 (file)
@@ -23,5 +23,12 @@ typedef void (*_eng_fn) (void);
 extern int  coregl_initialize();
 extern void coregl_terminate();
 
+extern unsigned int coregl_get_log_lvl();
+extern void coregl_set_log_lvl(unsigned int value);
+extern unsigned int coregl_get_dlog_enable();
+extern void coregl_set_dlog_enable(unsigned int value);
+extern unsigned int coregl_get_log_init();
+extern void coregl_set_log_init(unsigned int value);
+
 #endif // COREGL_H
 
index 8f2b16a..e48a964 100644 (file)
@@ -26,9 +26,6 @@
 #define LOG_TAG "COREGL"
 #include <dlog.h>
 
-unsigned int coregl_log_lvl;
-unsigned int coregl_dlog_enable;
-unsigned int coregl_log_initialized;
 
 #define FONT_DEFAULT   "\033[0m"       /* for reset to default color */
 #define FONT_RED               "\033[31m"      /* for error logs */
@@ -37,7 +34,7 @@ unsigned int coregl_log_initialized;
 
 #define coregl_log_e(t, f, x...)                                                                                       \
        do {                                                                                                                                    \
-               if(coregl_dlog_enable)                                                                                          \
+               if(coregl_get_dlog_enable())                                                                                            \
                        LOGE(FONT_RED t " " f FONT_DEFAULT, ##x);                                               \
                else                                                                                                                            \
                        fprintf(stderr, FONT_RED t "[(pid:%d)(%s)] " f FONT_DEFAULT "\n", getpid(), __func__, ##x);\
@@ -45,7 +42,7 @@ unsigned int coregl_log_initialized;
 
 #define coregl_log_w(t, f, x...)                                                                                       \
        do {                                                                                                                                    \
-               if(coregl_dlog_enable)                                                                                          \
+               if(coregl_get_dlog_enable())                                                                                            \
                        LOGW(FONT_YELLOW t " " f FONT_DEFAULT, ##x);                                    \
                else                                                                                                                            \
                        fprintf(stderr, FONT_YELLOW t "[(pid:%d)(%s)] " f FONT_DEFAULT "\n", getpid(), __func__, ##x);\
@@ -53,7 +50,7 @@ unsigned int coregl_log_initialized;
 
 #define coregl_log_d(t, f, x...)                                                                                       \
        do {                                                                                                                                    \
-               if(coregl_dlog_enable)                                                                                          \
+               if(coregl_get_dlog_enable())                                                                                            \
                        LOGD(FONT_GREEN t " " f FONT_DEFAULT, ##x);                                     \
                else                                                                                                                            \
                        fprintf(stderr, FONT_GREEN t "[(pid:%d)(%s)] " f FONT_DEFAULT "\n", getpid(), __func__, ##x);\
@@ -61,30 +58,31 @@ unsigned int coregl_log_initialized;
 
 #define LOG_INIT()                                                                             \
        do {                                                                                            \
-               if (!coregl_log_initialized) {                                  \
-                       char *lvl = (char *)getenv("COREGL_LOG_LEVEL"); \
-                       char *dlog = (char *)getenv("COREGL_TRACE_DLOG");\
-                       if (lvl)                                                                        \
-                               coregl_log_lvl = atoi(lvl);                             \
+               if (!coregl_get_log_init()) {                                   \
+                       char *lvl = (char *)getenv("COREGL_LOG_LEVEL");         \
+                       char *dlog = (char *)getenv("COREGL_TRACE_DLOG");       \
+                       if (lvl)                                                \
+                               coregl_set_log_lvl(atoi(lvl));                          \
                        else                                                                            \
-                               coregl_log_lvl = _COREGL_DEFAULT_LOG_LEVEL;\
+                               coregl_set_log_lvl(_COREGL_DEFAULT_LOG_LEVEL);\
                                                                                                                \
                        if (dlog)                                                                       \
-                               coregl_dlog_enable = atoi(dlog);                \
+                               coregl_set_dlog_enable(atoi(dlog));             \
                        else                                                                            \
-                               coregl_dlog_enable = _COREGL_DLOG_ENABLE;\
-                       coregl_log_initialized = 1;                                     \
+                               coregl_set_dlog_enable(_COREGL_DLOG_ENABLE);\
+                       coregl_set_log_init(1);                                 \
                }                                                                                               \
        }while(0)
 
 #define COREGL_ERR(f, x...)                                                            \
        do {                                                                                            \
                LOG_INIT();                                                                             \
-               if(coregl_dlog_enable)                                                  \
+               if(coregl_get_dlog_enable())                                                    \
                        coregl_log_e("[COREGL_ERROR]", f, ##x);         \
                else {                                                                                  \
-                       if (coregl_log_lvl > COREGL_LOG_INIT            \
-                               && coregl_log_lvl <= COREGL_LOG_ERR)    \
+                        unsigned int lvl = coregl_get_log_lvl();        \
+                       if (lvl > COREGL_LOG_INIT               \
+                               && lvl <= COREGL_LOG_ERR)       \
                                coregl_log_e("[COREGL_ERROR]", f, ##x); \
                }                                                                                               \
        }while(0)
@@ -92,11 +90,12 @@ unsigned int coregl_log_initialized;
 #define COREGL_WARN(f, x...)                                                   \
        do {                                                                                            \
                LOG_INIT();                                                                             \
-               if(coregl_dlog_enable)                                                  \
+               if(coregl_get_dlog_enable())                                                    \
                        coregl_log_w("[COREGL_WARN]", f, ##x);          \
                else {                                                                                  \
-                       if (coregl_log_lvl > COREGL_LOG_INIT            \
-                               && coregl_log_lvl <= COREGL_LOG_WARN)   \
+                        unsigned int lvl = coregl_get_log_lvl();        \
+                       if (lvl > COREGL_LOG_INIT               \
+                               && lvl <= COREGL_LOG_WARN)      \
                                coregl_log_w("[COREGL_WARN]", f, ##x);  \
                }                                                                                               \
        }while(0)
@@ -104,11 +103,12 @@ unsigned int coregl_log_initialized;
 #define COREGL_DBG(f, x...)                                                            \
        do {                                                                                            \
                LOG_INIT();                                                                             \
-               if(coregl_dlog_enable)                                                  \
+               if(coregl_get_dlog_enable())                                                    \
                        coregl_log_d("[COREGL_DBG]", f, ##x);           \
                else{                                                                                   \
-                       if (coregl_log_lvl > COREGL_LOG_INIT            \
-                               && coregl_log_lvl <= COREGL_LOG_DBG)    \
+                        unsigned int lvl = coregl_get_log_lvl();        \
+                       if (lvl > COREGL_LOG_INIT               \
+                               && lvl <= COREGL_LOG_DBG)       \
                                coregl_log_d("[COREGL_DBG]", f, ##x);   \
                }                                                                                               \
        }while(0)