From: Jeong Donghwan Date: Wed, 23 Nov 2016 12:01:54 +0000 (+0900) Subject: poll: modify pmlock manager data structure X-Git-Tag: accepted/tizen/3.0/common/20161130.065003^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eb89b8c41f1048e4a0febf2f804b72ac6c8f10ee;p=platform%2Fcore%2Fsystem%2Fdeviced.git poll: modify pmlock manager data structure PMLockNode structure used custom list. So it is modified to data structure providing from the library. Change-Id: I657e0be9224f4d5e4f18a52641cb9b716df11ae2 Signed-off-by: Jeong Donghwan --- diff --git a/src/display/core.c b/src/display/core.c index b2d61b3..9ffbcb5 100644 --- a/src/display/core.c +++ b/src/display/core.c @@ -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; } }