heart : delete after collecting candidates to prevent deadlock 28/130828/3
authorKichan Kwon <k_c.kwon@samsung.com>
Wed, 24 May 2017 00:44:38 +0000 (09:44 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 24 May 2017 09:20:32 +0000 (18:20 +0900)
- Both read_foreach and logging_delete locks cache mutex
- Therefore, logging_delete should be called after read_foreach
 is ended

Change-Id: I4a34fc4a26bc27e1739f1cfa4ce7331ed1fcab3b
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/heart/heart-storage.c

index 9f6f1e67edb120edc4e0feb073c59099f0285317..e4ccee002409753dbd91b7cd3faa9e928b66a4bd 100644 (file)
@@ -74,9 +74,10 @@ static void dbus_insert_log(GDBusMethodInvocation *invocation, GVariant *params)
        D_BUS_REPLY_NULL(invocation);
 }
 
-void heart_storage_delete_cb(struct logging_table_form *table, void *user_data)
+void heart_storage_delete_cb(gpointer data, gpointer user_data)
 {
        int ret;
+       struct logging_table_form *table = (struct logging_table_form *)data;
 
        if (!table) {
                _E("the table is empty!");
@@ -92,10 +93,27 @@ void heart_storage_delete_cb(struct logging_table_form *table, void *user_data)
                _SE("Delete request failed: %s", table->data);
 }
 
+void heart_storage_collect_candidate(struct logging_table_form *table, void *user_data)
+{
+       GPtrArray *candidates = (GPtrArray *)user_data;
+       if (!candidates) {
+               _E("There is no array to store candidates");
+               return;
+       }
+
+       g_ptr_array_add(candidates, table);
+}
+
 void *heart_storage_verifying_thread_main(void *arg)
 {
        int ret;
        char *pkgid;
+       GPtrArray *candidates = g_ptr_array_new();
+
+       if (!candidates) {
+               _E("Failed to create GPtrArray");
+               goto end;
+       }
 
        _D("Verifying thread is created!");
        do {
@@ -112,14 +130,20 @@ void *heart_storage_verifying_thread_main(void *arg)
                pthread_mutex_unlock(&heart_storage_verifying_mutex);
 
                _SD("Verify '%s'", pkgid);
-               ret = logging_read_foreach(STORAGE_NAME, NULL, pkgid, 0, 0, heart_storage_delete_cb, NULL);
+               ret = logging_read_foreach(STORAGE_NAME, NULL, pkgid, 0, 0,
+                               heart_storage_collect_candidate, candidates);
                if (ret != RESOURCED_ERROR_NONE)
                        _E("Failed to read logs! : %d", ret);
                free(pkgid);
+
+               g_ptr_array_foreach(candidates, heart_storage_delete_cb, NULL);
+               g_ptr_array_free(candidates, TRUE);
        } while (1);
 
-       heart_storage_verifying_thread = 0;
        pthread_mutex_unlock(&heart_storage_verifying_mutex);
+
+end:
+       heart_storage_verifying_thread = 0;
        pthread_exit((void *)0);
 }