block: Added logic to wait for thread processing on exit 24/203024/1
authorYunmi Ha <yunmi.ha@samsung.com>
Tue, 9 Apr 2019 05:29:15 +0000 (14:29 +0900)
committerYunmi Ha <yunmi.ha@samsung.com>
Tue, 9 Apr 2019 05:29:15 +0000 (14:29 +0900)
If the thread has remain job when it exit,
it need to wait for finishing it.

Change-Id: I09aba16ee427222537d279487711a4ecfbaff795
Signed-off-by: Yunmi Ha <yunmi.ha@samsung.com>
src/block/block.c
src/core/modules.c

index a649759..c78e3e8 100644 (file)
@@ -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();
index e742f2b..b2ac415 100644 (file)
@@ -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);