static GAsyncQueue * storage_queue;
static GAsyncQueue *scan_queue;
static GAsyncQueue *reg_queue;
-static GMutex scan_req_mutex;
static bool __msc_is_power_off(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)
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)
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");
}