poll: modify pmlock manager data structure 45/99645/2 accepted/tizen/3.0/common/20161130.065003 accepted/tizen/3.0/ivi/20161130.011858 accepted/tizen/3.0/mobile/20161130.011825 accepted/tizen/3.0/tv/20161130.011842 accepted/tizen/3.0/wearable/20161130.011851 submit/tizen_3.0/20161129.053222
authorJeong Donghwan <dh.jeong@samsung.com>
Wed, 23 Nov 2016 12:01:54 +0000 (21:01 +0900)
committerTaeyoung Kim <ty317.kim@samsung.com>
Tue, 29 Nov 2016 05:43:40 +0000 (21:43 -0800)
PMLockNode structure used custom list.
So it is modified to data structure providing from the library.

Change-Id: I657e0be9224f4d5e4f18a52641cb9b716df11ae2
Signed-off-by: Jeong Donghwan <dh.jeong@samsung.com>
src/display/core.c

index b2d61b3..9ffbcb5 100644 (file)
@@ -212,11 +212,10 @@ typedef struct _pm_lock_node {
        Ecore_Timer *timeout_id;
        time_t time;
        bool holdkey_block;
-       struct _pm_lock_node *next;
        bool background;
 } PmLockNode;
 
-static PmLockNode *cond_head[S_END];
+static dd_list *cond_head[S_END];
 
 static void set_process_active(bool flag, pid_t pid)
 {
@@ -241,12 +240,12 @@ static void set_process_active(bool flag, pid_t pid)
 
 bool check_lock_state(int state)
 {
-       PmLockNode *t = cond_head[state];
+       dd_list *elem;
+       PmLockNode *t;
 
-       while (t) {
+       DD_LIST_FOREACH(cond_head[state], elem, t) {
                if (t->background == false)
                        return true;
-               t = t->next;
        }
 
        return false;
@@ -471,14 +470,15 @@ static void makeup_trans_condition(void)
 
 static PmLockNode *find_node(enum state_t s_index, pid_t pid)
 {
-       PmLockNode *t = cond_head[s_index];
+       dd_list *elem;
+       PmLockNode *t;
 
-       while (t != NULL) {
+       DD_LIST_FOREACH(cond_head[s_index], elem, t) {
                if (t->pid == pid)
-                       break;
-               t = t->next;
+                       return t;
        }
-       return t;
+
+       return NULL;
 }
 
 static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeout_id,
@@ -498,9 +498,8 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeou
        n->timeout_id = timeout_id;
        n->time = now;
        n->holdkey_block = holdkey_block;
-       n->next = cond_head[s_index];
        n->background = false;
-       cond_head[s_index] = n;
+       DD_LIST_APPEND(cond_head[s_index], n);
 
        refresh_app_cond();
        return n;
@@ -508,35 +507,24 @@ static PmLockNode *add_node(enum state_t s_index, pid_t pid, Ecore_Timer *timeou
 
 static int del_node(enum state_t s_index, PmLockNode *n)
 {
-       PmLockNode *t;
-       PmLockNode *prev;
-
        if (n == NULL)
                return 0;
 
-       t = cond_head[s_index];
-       prev = NULL;
-       while (t != NULL) {
-               if (t == n) {
-                       if (prev != NULL)
-                               prev->next = t->next;
-                       else
-                               cond_head[s_index] = cond_head[s_index]->next;
-                       /* delete timer */
-                       if (t->timeout_id)
-                               ecore_timer_del(t->timeout_id);
-                       free(t);
-                       break;
-               }
-               prev = t;
-               t = t->next;
+       DD_LIST_REMOVE(cond_head[s_index], n);
+
+       /* delete timer */
+       if (n->timeout_id) {
+               ecore_timer_del(n->timeout_id);
+               n->timeout_id = NULL;
        }
+       free(n);
        refresh_app_cond();
        return 0;
 }
 
 static void print_node(int next)
 {
+       dd_list *elem;
        PmLockNode *n;
        char buf[30];
        time_t now;
@@ -546,8 +534,7 @@ static void print_node(int next)
                return;
 
        time(&now);
-       n = cond_head[next];
-       while (n != NULL) {
+       DD_LIST_FOREACH(cond_head[next], elem, n) {
                diff = difftime(now, n->time);
                ctime_r(&n->time, buf);
 
@@ -555,8 +542,6 @@ static void print_node(int next)
                        _W("over %.0f s, pid: %5d, lock time: %s", diff, n->pid, buf);
                else
                        _I("pid: %5d, lock time: %s", n->pid, buf);
-
-               n = n->next;
        }
 }
 
@@ -1014,11 +999,11 @@ static int proc_condition(PMMsg *data)
 /* If some changed, return 1 */
 int check_processes(enum state_t prohibit_state)
 {
-       PmLockNode *t = cond_head[prohibit_state];
-       PmLockNode *tmp = NULL;
+       dd_list *elem, *next;
+       PmLockNode *t;
        int ret = 0;
 
-       while (t != NULL) {
+       DD_LIST_FOREACH_SAFE(cond_head[prohibit_state], elem, next, t) {
                if (t->pid < INTERNAL_LOCK_BASE && kill(t->pid, 0) == -1) {
                        _E("%d process does not exist, delete the REQ"
                                " - prohibit state %d ",
@@ -1028,14 +1013,8 @@ int check_processes(enum state_t prohibit_state)
                                custom_normal_timeout = custom_dim_timeout = 0;
                                custom_change_pid = -1;
                        }
-                       tmp = t;
                        ret = 1;
-               }
-               t = t->next;
-
-               if (tmp != NULL) {
-                       del_node(prohibit_state, tmp);
-                       tmp = NULL;
+                       del_node(prohibit_state, t);
                }
        }
 
@@ -1044,7 +1023,8 @@ int check_processes(enum state_t prohibit_state)
 
 int check_holdkey_block(enum state_t state)
 {
-       PmLockNode *t = cond_head[state];
+       dd_list *elem;
+       PmLockNode *t;
        int ret = 0;
 
        _I("check holdkey block : state of %s", states[state].name);
@@ -1055,13 +1035,12 @@ int check_holdkey_block(enum state_t state)
                return 1;
        }
 
-       while (t != NULL) {
+       DD_LIST_FOREACH(cond_head[state], elem, t) {
                if (t->holdkey_block == true) {
                        ret = 1;
                        _I("Hold key blocked by pid(%d)!", t->pid);
                        break;
                }
-               t = t->next;
        }
 
        return ret;
@@ -1069,29 +1048,33 @@ int check_holdkey_block(enum state_t state)
 
 int delete_condition(enum state_t state)
 {
-       PmLockNode *t = cond_head[state];
-       PmLockNode *tmp = NULL;
+       dd_list *elem, *next;
+       PmLockNode *t;
        pid_t pid;
        char pname[PATH_MAX];
 
        _I("delete condition : state of %s", states[state].name);
 
-       while (t != NULL) {
+       if (!cond_head[state])
+               return 0;
+
+       DD_LIST_FOREACH_SAFE(cond_head[state], elem, next, t) {
                if (t->timeout_id > 0) {
                        ecore_timer_del(t->timeout_id);
                        t->timeout_id = NULL;
                }
-               tmp = t;
-               t = t->next;
-               pid = tmp->pid;
+               pid = t->pid;
                if (state == S_LCDOFF)
                        set_process_active(EINA_FALSE, pid);
                _I("delete node of pid(%d)", pid);
-               del_node(state, tmp);
+               del_node(state, t);
                get_pname(pid, pname);
                set_unlock_time(pname, state-1);
        }
 
+       DD_LIST_FREE_LIST(cond_head[state]);
+       cond_head[state] = NULL;
+
        return 0;
 }
 
@@ -1190,6 +1173,9 @@ void print_info(int fd)
        int i = 1;
        int ret;
        char pname[PATH_MAX];
+       PmLockNode *t;
+       dd_list *elem;
+       char time_buf[30];
 
        if (fd < 0)
                return;
@@ -1227,11 +1213,7 @@ void print_info(int fd)
                _E("write() failed (%d)", errno);
 
        for (s_index = S_NORMAL; s_index < S_END; s_index++) {
-               PmLockNode *t;
-               char time_buf[30];
-               t = cond_head[s_index];
-
-               while (t != NULL) {
+               DD_LIST_FOREACH(cond_head[s_index], elem, t) {
                        get_pname((pid_t)t->pid, pname);
                        ctime_r(&t->time, time_buf);
                        snprintf(buf, sizeof(buf),
@@ -1240,7 +1222,6 @@ void print_info(int fd)
                        ret = write(fd, buf, strlen(buf));
                        if (ret < 0)
                                _E("write() failed (%d)", errno);
-                       t = t->next;
                }
        }