From: Yunmi Ha Date: Tue, 9 Apr 2019 05:29:15 +0000 (+0900) Subject: block: Added logic to wait for thread processing on exit X-Git-Tag: submit/tizen/20190410.090025~1 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e85896764810388307b46f7ea11b7159d1df56ba;p=platform%2Fcore%2Fsystem%2Fstoraged.git block: Added logic to wait for thread processing on exit If the thread has remain job when it exit, it need to wait for finishing it. Change-Id: I09aba16ee427222537d279487711a4ecfbaff795 Signed-off-by: Yunmi Ha --- diff --git a/src/block/block.c b/src/block/block.c index a649759..c78e3e8 100644 --- a/src/block/block.c +++ b/src/block/block.c @@ -3719,12 +3719,34 @@ static void block_init(void *data) if (ret < 0) _E("Failed to get internal storage number."); } - -static void block_exit(void *data) +static void terminate_threads(void) { dd_list *elem, *elem_next; char *temp; - int ret, i; + int i, count; + const int WAIT_TIME = 10; + + for (i = 0; i < THREAD_MAX; i++) { + if (th_manager[i].start_th) { + count = 0; + while ((th_manager[i].op_len != 0) && (count < WAIT_TIME)) { + _I("Thread(%d) job is not finished. Wait a second.", th_manager[i].thread_id); + usleep(200*1000); + count++; + } + pthread_cancel(th_manager[i].th); + pthread_join(th_manager[i].th, NULL); + } + DD_LIST_FOREACH_SAFE(th_manager[i].th_node_list, elem, elem_next, temp) { + DD_LIST_REMOVE(th_manager[i].th_node_list, temp); + free(temp); + } + } +} + +static void block_exit(void *data) +{ + int ret; udev_exit(NULL); @@ -3740,14 +3762,7 @@ static void block_exit(void *data) /* remove remaining blocks */ remove_whole_block_device(); - for (i = 0; i < THREAD_MAX; i++) { - if (th_manager[i].start_th) - pthread_cancel(th_manager[i].th); - DD_LIST_FOREACH_SAFE(th_manager[i].th_node_list, elem, elem_next, temp) { - DD_LIST_REMOVE(th_manager[i].th_node_list, temp); - free(temp); - } - } + terminate_threads(); /* exit pipe */ pipe_exit(); diff --git a/src/core/modules.c b/src/core/modules.c index e742f2b..b2ac415 100644 --- a/src/core/modules.c +++ b/src/core/modules.c @@ -169,6 +169,7 @@ void modules_deinit(void *data) if (module->plugin && module->plugin->exit) module->plugin->exit(NULL); storaged_close_module(module->plugin); + _I("%s closed", module->so_name); free(module->name); free(module->so_name); free(module);