Update slave_activate_all/deactivate_all function.
authorSung-jae Park <nicesj.park@samsung.com>
Mon, 23 Sep 2013 23:33:01 +0000 (08:33 +0900)
committerSung-jae Park <nicesj.park@samsung.com>
Mon, 23 Sep 2013 23:33:01 +0000 (08:33 +0900)
counting call.
signal & low mem callback uses these API.

Change-Id: I565eda19feb94308011abf3f87b366a8cc3e685f

src/setting.c
src/slave_life.c

index 4e6d1c6..07e86d1 100644 (file)
@@ -15,6 +15,7 @@
  */
 
 #include <stdio.h>
+#include <malloc.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
 
 int errno;
 
+static struct {
+       int deactivated;
+} s_info = {
+       .deactivated = 0,
+};
+
 static void lcd_state_cb(keynode_t *node, void *user_data)
 {
        if (!node) {
@@ -211,6 +218,30 @@ out:
        DbgFree(event);
 }
 
+static void low_mem_cb(keynode_t *node, void *user_data)
+{
+       int val;
+
+       val = vconf_keynode_get_int(node);
+
+       if (val >= VCONFKEY_SYSMAN_LOW_MEMORY_SOFT_WARNING)     {
+               CRITICAL_LOG("Low memory: level %d\n", val);
+               if (s_info.deactivated == 0) {
+                       s_info.deactivated = 1;
+                       slave_deactivate_all(0, 1);
+                       malloc_trim(0);
+                       ErrPrint("Fall into the low mem status\n");
+               }
+       } else {
+               CRITICAL_LOG("Normal memory: level %d\n", val);
+               if (s_info.deactivated == 1) {
+                       s_info.deactivated = 0;
+                       slave_activate_all();
+                       ErrPrint("Recover from the low mem status\n");
+               }
+       }
+}
+
 HAPI int setting_init(void)
 {
        int ret;
@@ -240,6 +271,11 @@ HAPI int setting_init(void)
                ErrPrint("Failed to add vconf for ail info state: %d\n", ret);
        }
 
+       ret = vconf_notify_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb, NULL);
+       if (ret < 0) {
+               ErrPrint("Failed to add vconf for low mem monitor: %d\n", ret);
+       }
+
        lang_changed_cb(NULL, NULL);
        region_changed_cb(NULL, NULL);
        return ret;
@@ -249,6 +285,11 @@ HAPI int setting_fini(void)
 {
        int ret;
 
+       ret = vconf_ignore_key_changed(VCONFKEY_SYSMAN_LOW_MEMORY, low_mem_cb);
+       if (ret < 0) {
+               ErrPrint("Failed to ignore vconf key (%d)\n", ret);
+       }
+
        ret = vconf_ignore_key_changed(VCONFKEY_REGIONFORMAT, region_changed_cb);
        if (ret < 0) {
                ErrPrint("Failed to ignore vconf key (%d)\n", ret);
index f5710f6..383c8cc 100644 (file)
@@ -97,8 +97,10 @@ struct priv_data {
 
 static struct {
        Eina_List *slave_list;
+       int deactivate_all_refcnt;
 } s_info = {
        .slave_list = NULL,
+       .deactivate_all_refcnt = 0,
 };
 
 static Eina_Bool slave_ttl_cb(void *data)
@@ -1495,6 +1497,12 @@ HAPI int slave_deactivate_all(int reactivate, int reactivate_instances)
        struct slave_node *slave;
        int cnt = 0;
 
+       s_info.deactivate_all_refcnt++;
+       if (s_info.deactivate_all_refcnt > 1) {
+               return 0;
+       }
+       DbgPrint("Deactivate all\n");
+
        EINA_LIST_FOREACH_SAFE(s_info.slave_list, l, n, slave) {
                slave_set_reactivate_instances(slave, reactivate_instances);
                slave_set_reactivation(slave, reactivate);
@@ -1515,6 +1523,12 @@ HAPI int slave_activate_all(void)
        struct slave_node *slave;
        int cnt = 0;
 
+       s_info.deactivate_all_refcnt--;
+       if (s_info.deactivate_all_refcnt > 0) {
+               return 0;
+       }
+       DbgPrint("Activate all\n");
+
        EINA_LIST_FOREACH(s_info.slave_list, l, slave) {
                slave_activate(slave);
                cnt++;