Replaced all getenv() by tpl_getenv() to reduce unnecessary calls. 27/232027/1
authorJoonbum Ko <joonbum.ko@samsung.com>
Mon, 27 Apr 2020 11:36:18 +0000 (20:36 +0900)
committerJoonbum Ko <joonbum.ko@samsung.com>
Mon, 27 Apr 2020 11:36:34 +0000 (20:36 +0900)
 - In libtpl-egl, getenv() is using for debugging purposes only.
 - In most situations, it was frequently called getenv()
  which is not thread-safe, even though it is unnecessary.
 - It is difficult to make getenv() completely disabled,
  but replaced it with tpl_getenv() so that it can only be used
  in debugging situations.

 - tpl_getenv() returns the result of calling getenv()
  only if '/opt/usr/tpl_env' file exists, otherwise NULL.

 - example
  1. $ export TPL_LOG_LEVEL=3
  2. $ run gl app
    -> libtpl-egl will not get the env TPL_LOG_LEVEL

  3. $ touch /opt/usr/tpl_env
  4. $ run gl app
    -> TPL_LOG_LEVEL=3 will be accepted

Change-Id: I4d40e1beb2f4c34e17b7694f96db5d237cb33bfe
Signed-off-by: Joonbum Ko <joonbum.ko@samsung.com>
src/tpl.c
src/tpl_object.c
src/tpl_utils.h
src/tpl_wayland_egl.c
src/tpl_wayland_egl_thread.c
src/tpl_x11_dri2.c
src/tpl_x11_dri3.c

index 8107b8f..e6d90f0 100644 (file)
--- a/src/tpl.c
+++ b/src/tpl.c
@@ -231,11 +231,11 @@ __tpl_display_choose_backend(tpl_handle_t native_dpy)
        int wl_egl_thread = 0;
 #endif
 
-       thread = getenv("TPL_WL_EGL_THREAD");
+       thread = tpl_getenv("TPL_WL_EGL_THREAD");
        if (thread)
                wl_egl_thread = atoi(thread);
 
-       plat_name = getenv("EGL_PLATFORM");
+       plat_name = tpl_getenv("EGL_PLATFORM");
 
        if (plat_name) {
 #ifdef TPL_WINSYS_DRI2
index cf66cb0..4eb48c6 100644 (file)
@@ -11,7 +11,7 @@ __tpl_object_hash_init(void)
        char *val;
        tpl_obj_hash_check = TPL_FALSE;
 
-       val = getenv("TPL_OBJECT_HASH_CHECK");
+       val = tpl_getenv("TPL_OBJECT_HASH_CHECK");
        if ((val) && (!strcmp(val, "1")) && (!tpl_obj_hash)) {
                tpl_obj_hash_check = TPL_TRUE;
                tpl_obj_hash = __tpl_hashlist_create();
index 9e0369f..92cb6a0 100644 (file)
@@ -152,7 +152,7 @@ inline char *tpl_getenv(const char *name)
        {                                                                                                       \
                if (!tpl_log_initialized)                                               \
                {                                                                                               \
-                       char *env = getenv("TPL_LOG_LEVEL");            \
+                       char *env = tpl_getenv("TPL_LOG_LEVEL");                \
                        if (env == NULL)                                                        \
                                tpl_log_lvl = 0;                                                \
                        else                                                                            \
@@ -303,7 +303,7 @@ inline char *tpl_getenv(const char *name)
                }                                                                                                                                                               \
                else                                                                                                                                                    \
                {                                                                                                                                                               \
-                       char *env = getenv("TPL_DUMP_LEVEL");                                                                           \
+                       char *env = tpl_getenv("TPL_DUMP_LEVEL");                                                                               \
                        if (env == NULL)                                                                                                                        \
                                tpl_dump_lvl = 0;                                                                                                               \
                        else                                                                                                                                            \
index d3d4d38..19611a7 100755 (executable)
@@ -173,7 +173,7 @@ __tpl_wayland_egl_display_init(tpl_display_t *display)
                        (struct wl_display *)display->native_handle;
                wayland_egl_display->wl_tbm_client =
                        wayland_tbm_client_init((struct wl_display *) wl_dpy);
-               char *env = getenv("TPL_WAIT_VBLANK");
+               char *env = tpl_getenv("TPL_WAIT_VBLANK");
 
                if (!wayland_egl_display->wl_tbm_client) {
                        TPL_ERR("Wayland TBM initialization failed!");
index 79bcb91..6722970 100755 (executable)
@@ -532,7 +532,7 @@ twe_thread_create(void)
 
                _twe_ctx->use_wait_vblank = TPL_TRUE;
 
-               env = getenv("TPL_WAIT_VBLANK");
+               env = tpl_getenv("TPL_WAIT_VBLANK");
                if (env && !atoi(env)) {
                        _twe_ctx->use_wait_vblank = TPL_FALSE;
                }
index c38f2c7..e5480a7 100644 (file)
@@ -207,10 +207,10 @@ __tpl_x11_dri2_display_init(tpl_display_t *display)
                global.bufmgr = tbm_bufmgr_init(global.bufmgr_fd);
 
                /* Initialize swap type configuration. */
-               __tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_WINDOW_SWAP_TYPE_ENV_NAME),
+               __tpl_x11_swap_str_to_swap_type(tpl_getenv(EGL_X11_WINDOW_SWAP_TYPE_ENV_NAME),
                                                                                &global.win_swap_type);
 
-               __tpl_x11_swap_str_to_swap_type(getenv(EGL_X11_FB_SWAP_TYPE_ENV_NAME),
+               __tpl_x11_swap_str_to_swap_type(tpl_getenv(EGL_X11_FB_SWAP_TYPE_ENV_NAME),
                                                                                &global.fb_swap_type);
        }
 
index 076446b..3f90de3 100644 (file)
@@ -1237,7 +1237,7 @@ __tpl_x11_dri3_display_init(tpl_display_t *display)
                {
                        const char *backend_env = NULL;
                        int count = 0;
-                       backend_env = getenv("MALI_EGL_DRI3_BUF_NUM");
+                       backend_env = tpl_getenv("MALI_EGL_DRI3_BUF_NUM");
                        /* 2015-05-13 joonbum.ko@samsung.com */
                        /* Change the value of dri3_max_back 5 to 3 */
                        if (!backend_env || strlen(backend_env) == 0)