Modified flushing memory logic 16/184416/6
authorHwankyu Jhun <h.jhun@samsung.com>
Wed, 18 Jul 2018 02:24:41 +0000 (11:24 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Wed, 25 Jul 2018 03:00:49 +0000 (12:00 +0900)
elm_cache_all_flush() is separated from appcore_base_flush_memory().
And, trim_memory() callback function type is added to add entry point.
appcore_base_on_trim_memory() is also added.

Change-Id: Ie2485468554d4e573e049f03d62ed5cb9ac78eaa
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
include/appcore_base.h
include/appcore_efl_base.h
include/appcore_multiwindow_base.h
include/appcore_ui_base.h
src/base/appcore_base.c
src/efl_base/appcore_efl_base.c
src/multiwindow_base/appcore_multiwindow_base.c
src/multiwindow_base/appcore_multiwindow_base_window.c
src/ui_base/appcore_ui_base.c

index 3fb216e..bd8154d 100644 (file)
@@ -66,6 +66,7 @@ typedef struct _appcore_base_ops {
        void (*exit)(void *data);
        void (*set_event)(enum appcore_base_event event, void *data);
        void (*unset_event)(enum appcore_base_event event, void *data);
+       void (*trim_memory)(void *data);
 } appcore_base_ops;
 
 int appcore_base_on_receive(aul_type type, bundle *b);
@@ -75,6 +76,7 @@ int appcore_base_on_terminate(void);
 int appcore_base_on_set_i18n(void);
 void appcore_base_on_set_event(enum appcore_base_event event);
 void appcore_base_on_unset_event(enum appcore_base_event event);
+int appcore_base_on_trim_memory(void);
 int appcore_base_init(appcore_base_ops ops, int argc, char **argv, void *data);
 void appcore_base_fini(void);
 appcore_base_ops appcore_base_get_default_ops(void);
index d902130..8cff47f 100644 (file)
@@ -44,6 +44,7 @@ int appcore_efl_base_on_terminate(void);
 int appcore_efl_base_on_pause(void);
 int appcore_efl_base_on_resume(void);
 int appcore_efl_base_on_control(bundle *b);
+int appcore_efl_base_on_trim_memory(void);
 void appcore_efl_base_window_on_show(int type, void *event);
 void appcore_efl_base_window_on_hide(int type, void *event);
 void appcore_efl_base_window_on_lower(int type, void *event);
index cb439a8..2b3c181 100644 (file)
@@ -61,6 +61,7 @@ int appcore_multiwindow_base_on_receive(aul_type type, bundle *b);
 int appcore_multiwindow_base_on_create(void);
 int appcore_multiwindow_base_on_terminate(void);
 int appcore_multiwindow_base_on_control(bundle *b);
+int appcore_multiwindow_base_on_trim_memory(void);
 void appcore_multiwindow_base_window_on_show(int type, void *event);
 void appcore_multiwindow_base_window_on_hide(int type, void *event);
 void appcore_multiwindow_base_window_on_lower(int type, void *event);
@@ -68,6 +69,7 @@ void appcore_multiwindow_base_window_on_visibility(int type, void *event);
 void appcore_multiwindow_base_window_on_pre_visibility(int type, void *event);
 void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Ecore_Wl2_Window *wl_win);
 void appcore_multiwindow_base_window_unbind(appcore_multiwindow_base_instance_h h);
+bool appcore_multiwindow_base_window_is_resumed(void);
 
 appcore_multiwindow_base_class appcore_multiwindow_base_class_get_default(void);
 void appcore_multiwindow_base_class_add(appcore_multiwindow_base_class cls);
index f85f727..f787082 100644 (file)
@@ -55,6 +55,7 @@ int appcore_ui_base_on_terminate(void);
 int appcore_ui_base_on_pause(void);
 int appcore_ui_base_on_resume(void);
 int appcore_ui_base_on_control(bundle *b);
+int appcore_ui_base_on_trim_memory(void);
 void appcore_ui_base_window_on_show(int type, void *event);
 void appcore_ui_base_window_on_hide(int type, void *event);
 void appcore_ui_base_window_on_lower(int type, void *event);
index 1754f07..dfc6f2c 100644 (file)
@@ -791,7 +791,9 @@ static gboolean __flush_memory(gpointer data)
 {
        int suspend = APPCORE_BASE_SUSPENDED_STATE_WILL_ENTER_SUSPEND;
 
-       appcore_base_flush_memory();
+       if (__context.ops.trim_memory)
+               __context.ops.trim_memory(__context.data);
+
        __context.tid = 0;
 
        if (!__context.allowed_bg && !__context.suspended_state) {
@@ -1139,19 +1141,9 @@ EXPORT_API void appcore_base_fini(void)
 
 EXPORT_API int appcore_base_flush_memory(void)
 {
-       int (*sqlite3_free_heap_memory)(int);
-       void (*elm_free_all_cache)(void);
+       if (__context.ops.trim_memory)
+               __context.ops.trim_memory(__context.data);
 
-       elm_free_all_cache = dlsym(RTLD_DEFAULT, "elm_cache_all_flush");
-       if (elm_free_all_cache)
-               elm_free_all_cache();
-
-       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
-                       "sqlite3_release_memory");
-       if (sqlite3_free_heap_memory)
-               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
-
-       malloc_trim(0);
        return 0;
 }
 
@@ -1303,6 +1295,20 @@ EXPORT_API void appcore_base_on_unset_event(enum appcore_base_event event)
        }
 }
 
+EXPORT_API int appcore_base_on_trim_memory(void)
+{
+       int (*sqlite3_free_heap_memory)(int);
+
+       sqlite3_free_heap_memory = dlsym(RTLD_DEFAULT,
+                       "sqlite3_release_memory");
+       if (sqlite3_free_heap_memory)
+               sqlite3_free_heap_memory(SQLITE_FLUSH_MAX);
+
+       malloc_trim(0);
+
+       return 0;
+}
+
 EXPORT_API appcore_base_event_h appcore_base_add_event(enum appcore_base_event event,
                appcore_base_event_cb cb, void *data)
 {
@@ -1421,12 +1427,17 @@ static int __on_set_i18n(void *data)
 
 static void __on_set_event(enum appcore_base_event event, void *data)
 {
-       return appcore_base_on_set_event(event);
+       appcore_base_on_set_event(event);
 }
 
 static void __on_unset_event(enum appcore_base_event event, void *data)
 {
-       return appcore_base_on_unset_event(event);
+       appcore_base_on_unset_event(event);
+}
+
+static void __on_trim_memory(void *data)
+{
+       appcore_base_on_trim_memory();
 }
 
 EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
@@ -1444,6 +1455,7 @@ EXPORT_API appcore_base_ops appcore_base_get_default_ops(void)
        ops.exit = NULL;
        ops.set_event = __on_set_event;
        ops.unset_event = __on_unset_event;
+       ops.trim_memory = __on_trim_memory;
 
        return ops;
 }
index d193f38..b8880ea 100644 (file)
@@ -193,6 +193,13 @@ static void __efl_app_exit(void *data)
        elm_exit();
 }
 
+static void __efl_app_trim_memory(void *data)
+{
+       _DBG("Trim memory");
+       elm_cache_all_flush();
+       appcore_base_on_trim_memory();
+}
+
 EXPORT_API int appcore_efl_base_init(appcore_efl_base_ops ops, int argc,
                char **argv, void *data, unsigned int hint)
 {
@@ -215,6 +222,7 @@ EXPORT_API appcore_efl_base_ops appcore_efl_base_get_default_ops(void)
        ops.ui_base.base.finish = __efl_app_finish;
        ops.ui_base.base.run = __efl_app_run;
        ops.ui_base.base.exit = __efl_app_exit;
+       ops.ui_base.base.trim_memory = __efl_app_trim_memory;
 
        return ops;
 }
@@ -249,6 +257,11 @@ EXPORT_API int appcore_efl_base_on_control(bundle *b)
        return appcore_ui_base_on_control(b);
 }
 
+EXPORT_API int appcore_efl_base_on_trim_memory(void)
+{
+       return appcore_ui_base_on_trim_memory();
+}
+
 EXPORT_API void appcore_efl_base_window_on_show(int type, void *event)
 {
        appcore_ui_base_window_on_show(type, event);
index dd4fee0..e6eef8e 100644 (file)
 #include "appcore_multiwindow_base_private.h"
 
 appcore_multiwindow_base_context _appcore_mw_context;
+static guint __flush_timer = 0;
+
+static gboolean __flush_memory(gpointer data)
+{
+       _DBG("Flush memory");
+       if (_appcore_mw_context.ops.base.trim_memory)
+               _appcore_mw_context.ops.base.trim_memory(_appcore_mw_context.data);
+       __flush_timer = 0;
+       return G_SOURCE_REMOVE;
+}
+
+static void __add_flush_timer(void)
+{
+       if (__flush_timer)
+               return;
+
+       __flush_timer = g_timeout_add(5000, __flush_memory, NULL);
+}
+
+static void __remove_flush_timer(void)
+{
+       if (!__flush_timer)
+               return;
+
+       g_source_remove(__flush_timer);
+       __flush_timer = 0;
+}
 
 static Eina_Bool __stub_show_cb(void *data, int type, void *event)
 {
@@ -56,9 +83,18 @@ static Eina_Bool __stub_hide_cb(void *data, int type, void *event)
 
 static Eina_Bool __stub_visibility_cb(void *data, int type, void *event)
 {
+       Ecore_Wl2_Event_Window_Visibility_Change *ev = event;
+
        if (_appcore_mw_context.ops.window.visibility)
                _appcore_mw_context.ops.window.visibility(type, event, _appcore_mw_context.data);
 
+       if (ev && ev->fully_obscured) {
+               if (!appcore_multiwindow_base_window_is_resumed())
+                       __add_flush_timer();
+       } else {
+               __remove_flush_timer();
+       }
+
        return ECORE_CALLBACK_RENEW;
 }
 
@@ -72,9 +108,14 @@ static Eina_Bool __stub_lower_cb(void *data, int type, void *event)
 
 static Eina_Bool __stub_pre_visibility_cb(void *data, int type, void *event)
 {
+       Ecore_Wl2_Event_Window_Pre_Visibility_Change *ev = event;
+
        if (_appcore_mw_context.ops.window.pre_visibility)
                _appcore_mw_context.ops.window.pre_visibility(type, event, _appcore_mw_context.data);
 
+       if (ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED)
+               __remove_flush_timer();
+
        return ECORE_CALLBACK_RENEW;
 }
 
@@ -166,6 +207,11 @@ static int __on_terminate(void *data)
        return appcore_multiwindow_base_on_terminate();
 }
 
+static void __on_trim_memory(void *data)
+{
+       appcore_multiwindow_base_on_trim_memory();
+}
+
 static void __window_on_show(int type, void *event, void *data)
 {
        appcore_multiwindow_base_window_on_show(type, event);
@@ -205,6 +251,7 @@ EXPORT_API appcore_multiwindow_base_ops appcore_multiwindow_base_get_default_ops
        ops.base.finish = NULL;
        ops.base.run = NULL;
        ops.base.exit = NULL;
+       ops.base.trim_memory = __on_trim_memory;
 
        ops.window.show = __window_on_show;
        ops.window.hide = __window_on_hide;
@@ -251,3 +298,7 @@ EXPORT_API int appcore_multiwindow_base_on_control(bundle *b)
        return 0;
 }
 
+EXPORT_API int appcore_multiwindow_base_on_trim_memory(void)
+{
+       return appcore_base_on_trim_memory();
+}
index 2d3d010..9502c81 100644 (file)
@@ -37,7 +37,6 @@ typedef struct _win_context {
 } win_context;
 
 static GList *__win_contexts;
-static guint __flush_timer;
 
 static gint __comp(gconstpointer a, gconstpointer b)
 {
@@ -86,7 +85,7 @@ static win_context *__find_win_context_by_wid(int wid)
        return node->data;
 }
 
-static bool __is_resumed(void)
+EXPORT_API bool appcore_multiwindow_base_window_is_resumed(void)
 {
        win_context *ctx;
        GList *iter;
@@ -102,31 +101,6 @@ static bool __is_resumed(void)
        return false;
 }
 
-static gboolean __flush_memory(gpointer data)
-{
-       _DBG("Flush memory");
-       appcore_base_flush_memory();
-       __flush_timer = 0;
-       return G_SOURCE_REMOVE;
-}
-
-static void __add_flush_timer(void)
-{
-       if (__flush_timer)
-               return;
-
-       __flush_timer = g_timeout_add(5000, __flush_memory, NULL);
-}
-
-static void __remove_flush_timer(void)
-{
-       if (!__flush_timer)
-               return;
-
-       g_source_remove(__flush_timer);
-       __flush_timer = 0;
-}
-
 EXPORT_API void appcore_multiwindow_base_window_on_show(int type, void *event)
 {
 }
@@ -155,14 +129,10 @@ EXPORT_API void appcore_multiwindow_base_window_on_visibility(int type, void *ev
        if (!cxt)
                return;
 
-       if (ev->fully_obscured) {
+       if (ev->fully_obscured)
                appcore_multiwindow_base_instance_pause(cxt->inst);
-               if (!__is_resumed())
-                       __add_flush_timer();
-       } else {
+       else
                appcore_multiwindow_base_instance_resume(cxt->inst);
-               __remove_flush_timer();
-       }
 }
 
 EXPORT_API void appcore_multiwindow_base_window_on_pre_visibility(int type, void *event)
@@ -173,10 +143,8 @@ EXPORT_API void appcore_multiwindow_base_window_on_pre_visibility(int type, void
        if (!cxt)
                return;
 
-       if (ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED) {
+       if (ev->type == ECORE_WL2_WINDOW_VISIBILITY_TYPE_PRE_UNOBSCURED)
                appcore_multiwindow_base_instance_resume(cxt->inst);
-               __remove_flush_timer();
-       }
 }
 
 EXPORT_API void appcore_multiwindow_base_window_bind(appcore_multiwindow_base_instance_h h, Ecore_Wl2_Window *wl_win)
index 944b312..8b83a1a 100644 (file)
@@ -746,6 +746,11 @@ EXPORT_API int appcore_ui_base_on_control(bundle *b)
        return 0;
 }
 
+EXPORT_API int appcore_ui_base_on_trim_memory(void)
+{
+       return appcore_base_on_trim_memory();
+}
+
 static void __group_attach()
 {
        if (!(__context.hint & APPCORE_UI_BASE_HINT_WINDOW_GROUP_CONTROL))