From: Geunhae LEE Date: Mon, 12 May 2014 12:12:24 +0000 (+0900) Subject: ecs : make client list thread-safe use QTAIL_FOREACH_SAFE instead of QTAIL_FOREACH... X-Git-Tag: TizenStudio_2.0_p2.3~238^2~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F36%2F21136%2F2;p=sdk%2Femulator%2Fqemu.git ecs : make client list thread-safe use QTAIL_FOREACH_SAFE instead of QTAIL_FOREACH not to call ecs_close in stop_ecs (FIXME) Change-Id: I76dfbd3c4e97fd925f0d1108c034f9eecf05f5c7 Signed-off-by: Geunhae LEE --- diff --git a/tizen/src/ecs/ecs.c b/tizen/src/ecs/ecs.c index ef50442..758ae15 100644 --- a/tizen/src/ecs/ecs.c +++ b/tizen/src/ecs/ecs.c @@ -122,9 +122,9 @@ bool send_to_all_client(const char* data, const int len) { TRACE("data len: %d, data: %s\n", len, data); pthread_mutex_lock(&mutex_clilist); - ECS_Client *clii; + ECS_Client *clii,*next; - QTAILQ_FOREACH(clii, &clients, next) + QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { send_to_client(clii->client_fd, data, len); } @@ -197,7 +197,7 @@ static Monitor *monitor_create(void) { } static void ecs_close(ECS_State *cs) { - ECS_Client *clii; + ECS_Client *clii, *next; INFO("### Good bye! ECS ###\n"); if (cs == NULL) @@ -223,7 +223,7 @@ static void ecs_close(ECS_State *cs) { cs->alive_timer = NULL; } - QTAILQ_FOREACH(clii, &clients, next) + QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { ecs_client_close(clii); } @@ -369,9 +369,9 @@ static void epoll_cli_add(ECS_State *cs, int fd) { #endif static ECS_Client *ecs_find_client(int fd) { - ECS_Client *clii; + ECS_Client *clii, *next; - QTAILQ_FOREACH(clii, &clients, next) + QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { if (clii->client_fd == fd) return clii; @@ -380,9 +380,9 @@ static ECS_Client *ecs_find_client(int fd) { } ECS_Client *find_client(unsigned char id, unsigned char type) { - ECS_Client *clii; + ECS_Client *clii, *next; - QTAILQ_FOREACH(clii, &clients, next) + QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { if (clii->client_id == id && clii->client_type == type) return clii; @@ -513,13 +513,13 @@ static void make_keep_alive_msg(void) { static void alive_checker(void *opaque) { - ECS_Client *clii; + ECS_Client *clii, *next; if (NULL != current_ecs && !current_ecs->ecs_running) { return; } - QTAILQ_FOREACH(clii, &clients, next) + QTAILQ_FOREACH_SAFE(clii, &clients, next, next) { if (1 == clii->keep_alive) { INFO("get client fd %d - keep alive fail\n", clii->client_fd); @@ -619,17 +619,14 @@ static int ecs_loop(ECS_State *cs) for (index = 0; index < cs->reads.fd_count; index++) { if (cs->reads.fd_array == NULL) continue; - if (FD_ISSET(cs->reads.fd_array[index], &temps)) { if (cs->reads.fd_array[index] == cs->listen_fd) { ecs_accept(cs); continue; } - ecs_read(ecs_find_client(cs->reads.fd_array[index])); } } - return 0; } #elif defined(CONFIG_DARWIN) @@ -729,7 +726,7 @@ int stop_ecs(void) { INFO("ecs is closing.\n"); if (NULL != current_ecs) { current_ecs->ecs_running = 0; - ecs_close(current_ecs); + // ecs_close(current_ecs); } pthread_mutex_destroy(&mutex_clilist);