Fix multiple cancellation bug 73/242973/5
authorMinje Ahn <minje.ahn@samsung.com>
Wed, 2 Sep 2020 06:46:00 +0000 (15:46 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 2 Sep 2020 08:00:14 +0000 (08:00 +0000)
Modified to cancel only one item.

Change-Id: I202d5c4093b6af420a4120c7d919dd16b384b1d7
Signed-off-by: Minje Ahn <minje.ahn@samsung.com>
src/scanner/media-scanner-scan.c
src/server/media-server-socket.c

index 5e9ecfb..aa30b10 100644 (file)
@@ -34,7 +34,6 @@ static bool power_off;
 static GAsyncQueue * storage_queue;
 static GAsyncQueue *scan_queue;
 static GAsyncQueue *reg_queue;
-static GMutex scan_req_mutex;
 
 static bool __msc_is_power_off(void)
 {
@@ -582,10 +581,6 @@ void msc_init_scanner(void)
        if (!scan_queue) scan_queue = g_async_queue_new();
        if (!reg_queue) reg_queue = g_async_queue_new();
        if (!storage_queue) storage_queue = g_async_queue_new();
-
-       /*Init mutex variable*/
-       g_mutex_init(&scan_req_mutex);
-
 }
 
 void msc_deinit_scanner(void)
@@ -593,10 +588,6 @@ void msc_deinit_scanner(void)
        if (scan_queue) g_async_queue_unref(scan_queue);
        if (reg_queue) g_async_queue_unref(reg_queue);
        if (storage_queue) g_async_queue_unref(storage_queue);
-
-       /*Clear db mutex variable*/
-       g_mutex_clear(&scan_req_mutex);
-
 }
 
 int msc_push_scan_request(ms_scan_type_e scan_type, ms_comm_msg_s *recv_msg)
@@ -655,34 +646,23 @@ void msc_send_power_off_request(void)
 
 void msc_remove_dir_scan_request(ms_comm_msg_s *recv_msg)
 {
-       int i = 0;
+       bool found_item = false;
        ms_comm_msg_s *msg = NULL;
-       GAsyncQueue *temp_scan_queue = NULL;
-       int queue_len = g_async_queue_length(scan_queue);
+       int items_to_find = g_async_queue_length(scan_queue);
 
-       if (queue_len == 0) {
+       if (items_to_find == 0) {
                MS_DBG_ERR("Request is not stacked");
                return;
        }
 
-       MS_DBG_WARN("scan_req_mutex is LOCKED");
-       g_mutex_lock(&scan_req_mutex);
-
-       temp_scan_queue = g_async_queue_new();
-
-       for (i = 0; i < queue_len; i++) {
-               /*create new queue to compare request*/
+       while (items_to_find-- > 0) {
                msg = g_async_queue_pop(scan_queue);
-               if ((g_strcmp0(msg->msg, recv_msg->msg) == 0) && (recv_msg->pid == msg->pid)) {
-                       MS_DBG("Find request. Remove it");
+               if (!found_item && (g_strcmp0(msg->msg, recv_msg->msg) == 0) && (recv_msg->pid == msg->pid)) {
+                       MS_DBG("Found item. Remove it");
                        g_free(msg);
+                       found_item = true;
                } else {
-                       g_async_queue_push(temp_scan_queue, msg);
+                       g_async_queue_push(scan_queue, msg);
                }
        }
-       g_async_queue_unref(scan_queue);
-       scan_queue = temp_scan_queue;
-
-       g_mutex_unlock(&scan_req_mutex);
-       MS_DBG_WARN("scan_req_mutex is UNLOCKED");
 }
index f94f2e6..108fbfa 100644 (file)
@@ -95,7 +95,7 @@ static void __ms_delete_owner(int pid, const char *req_path)
                return;
 
        for (i = 0; i < owner_list->len; i++) {
-               data = g_array_index(owner_list, ms_req_owner_data*, i);
+               data = g_array_index(owner_list, ms_req_owner_data *, i);
                if (data->pid == pid && (strcmp(data->req_path, req_path) == 0)) {
                        MS_DBG("OWNER FOUND");
                        g_array_remove_index(owner_list, i);