From d29ee599373eae8cb83236405374fde1f8efc84d Mon Sep 17 00:00:00 2001 From: Hwankyu Jhun Date: Wed, 22 Jul 2020 12:56:07 +0900 Subject: [PATCH] Fix Memory Monitor If previous memory status is equal to current memory status, the callback function is not called. Change-Id: Ie5c96ef10e19a4f0614b33ec6331ef0db01349c5 Signed-off-by: Hwankyu Jhun --- src/launchpad/src/launchpad_memory_monitor.c | 28 ++++++++++------------------ 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/src/launchpad/src/launchpad_memory_monitor.c b/src/launchpad/src/launchpad_memory_monitor.c index dacf3ab..bc99ec1 100644 --- a/src/launchpad/src/launchpad_memory_monitor.c +++ b/src/launchpad/src/launchpad_memory_monitor.c @@ -33,6 +33,7 @@ struct memory_monitor_s { unsigned int prev_used_ratio; unsigned int base_interval; unsigned int interval; + bool low_memory; guint tag; memory_monitor_cb callback; void *user_data; @@ -44,27 +45,14 @@ static void __memory_monitor_start(void); static gboolean __memory_check_cb(gpointer data) { - unsigned int mem_used_ratio = 0; - int ret; + bool low_memory; __monitor.tag = 0; - ret = _proc_get_mem_used_ratio(&mem_used_ratio); - if (ret != 0) { - _E("Failed to get mem used ratio"); - __monitor.interval = __monitor.base_interval; - __memory_monitor_start(); - return G_SOURCE_REMOVE; - } - - if (__monitor.callback) { - __monitor.callback(mem_used_ratio > __monitor.threshold, - __monitor.user_data); - } - - _D("previous used ratio(%u), current used ratio(%u)", - __monitor.prev_used_ratio, mem_used_ratio); + low_memory = _memory_monitor_is_low_memory(); + if (__monitor.low_memory != low_memory && __monitor.callback) + __monitor.callback(low_memory, __monitor.user_data); - __monitor.prev_used_ratio = mem_used_ratio; + __monitor.low_memory = low_memory; __memory_monitor_start(); return G_SOURCE_REMOVE; @@ -106,6 +94,10 @@ bool _memory_monitor_is_low_memory(void) unsigned int mem_used_ratio = 0; _proc_get_mem_used_ratio(&mem_used_ratio); + + _D("previous used ratio(%u), current used ratio(%u)", + __monitor.prev_used_ratio, mem_used_ratio); + __monitor.prev_used_ratio = mem_used_ratio; if (mem_used_ratio > __monitor.threshold) -- 2.7.4