Repository: celix Updated Branches: refs/heads/develop f7779cc84 -> 83b124ffd
CELIX-438: Replaces linked link usage to celix_array_list in dm_component Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/83b124ff Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/83b124ff Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/83b124ff Branch: refs/heads/develop Commit: 83b124ffd891453c7957bd11b27e1b875c74e4dc Parents: f7779cc Author: Pepijn Noltes <[email protected]> Authored: Tue Dec 4 20:09:06 2018 +0100 Committer: Pepijn Noltes <[email protected]> Committed: Tue Dec 4 20:09:06 2018 +0100 ---------------------------------------------------------------------- libs/framework/src/dm_component_impl.c | 46 ++++++++++++------------ libs/utils/include/linked_list.h | 56 ++++++++++++++++------------- 2 files changed, 54 insertions(+), 48 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/83b124ff/libs/framework/src/dm_component_impl.c ---------------------------------------------------------------------- diff --git a/libs/framework/src/dm_component_impl.c b/libs/framework/src/dm_component_impl.c index f6ec79e..0b82c3f 100644 --- a/libs/framework/src/dm_component_impl.c +++ b/libs/framework/src/dm_component_impl.c @@ -72,7 +72,7 @@ typedef struct dm_interface_struct { struct dm_executor_struct { pthread_t runningThread; bool runningThreadSet; - linked_list_pt workQueue; + celix_array_list_t *workQueue; pthread_mutex_t mutex; }; @@ -1334,7 +1334,7 @@ static celix_status_t executor_create(celix_dm_component_t *component __attribut if (!*executor) { status = CELIX_ENOMEM; } else { - linkedList_create(&(*executor)->workQueue); + (*executor)->workQueue = celix_arrayList_create(); pthread_mutex_init(&(*executor)->mutex, NULL); (*executor)->runningThreadSet = false; } @@ -1346,7 +1346,7 @@ static void executor_destroy(dm_executor_pt executor) { if (executor) { pthread_mutex_destroy(&executor->mutex); - linkedList_destroy(executor->workQueue); + celix_arrayList_destroy(executor->workQueue); free(executor); } @@ -1365,7 +1365,7 @@ static celix_status_t executor_schedule(dm_executor_pt executor, celix_dm_compon task->data = data; pthread_mutex_lock(&executor->mutex); - linkedList_addLast(executor->workQueue, task); + celix_arrayList_add(executor->workQueue, task); pthread_mutex_unlock(&executor->mutex); } @@ -1414,28 +1414,28 @@ static celix_status_t executor_runTasks(dm_executor_pt executor, pthread_t curre celix_status_t status = CELIX_SUCCESS; // bool execute = false; - do { - dm_executor_task_t *entry = NULL; - pthread_mutex_lock(&executor->mutex); - while ((entry = linkedList_removeFirst(executor->workQueue)) != NULL) { - pthread_mutex_unlock(&executor->mutex); - - entry->command(entry->component, entry->data); + dm_executor_task_t *entry = NULL; - pthread_mutex_lock(&executor->mutex); + pthread_mutex_lock(&executor->mutex); + int size = celix_arrayList_size(executor->workQueue); + celix_array_list_t *localQueue = celix_arrayList_create(); //TODO add reserve or create with cap + for (int i = 0; i < size; ++i) { + celix_arrayList_add(localQueue, celix_arrayList_get(executor->workQueue, i)); + } + celix_arrayList_clear(executor->workQueue); + pthread_mutex_unlock(&executor->mutex); - free(entry); - } - executor->runningThreadSet = false; - pthread_mutex_unlock(&executor->mutex); + size = celix_arrayList_size(localQueue); + for (int i = 0; i < size; ++i) { + entry = celix_arrayList_get(localQueue, i); + entry->command(entry->component, entry->data); + free(entry); + } + celix_arrayList_destroy(localQueue); -// pthread_mutex_lock(&executor->mutex); -// if (executor->runningThread == NULL) { -// executor->runningThread = currentThread; -// execute = true; -// } -// pthread_mutex_unlock(&executor->mutex); - } while (!linkedList_isEmpty(executor->workQueue)); // && execute + pthread_mutex_lock(&executor->mutex); + executor->runningThreadSet = false; + pthread_mutex_unlock(&executor->mutex); return status; } http://git-wip-us.apache.org/repos/asf/celix/blob/83b124ff/libs/utils/include/linked_list.h ---------------------------------------------------------------------- diff --git a/libs/utils/include/linked_list.h b/libs/utils/include/linked_list.h index cbf650c..04c1162 100644 --- a/libs/utils/include/linked_list.h +++ b/libs/utils/include/linked_list.h @@ -32,57 +32,63 @@ #include "celix_errno.h" #include "exports.h" +#ifdef ADD_CELIX_DEPRECATED_WARNING +#define CELIX_DEPRECATED_ATTR __attribute__ ((deprecated)) +#else +#define CELIX_DEPRECATED_ATTR +#endif + #ifdef __cplusplus extern "C" { #endif -typedef struct linked_list_entry *linked_list_entry_pt; -typedef struct linked_list *linked_list_pt; +typedef struct linked_list_entry *linked_list_entry_pt; //TODO make deprecated +typedef struct linked_list *linked_list_pt; //TODO make deprecated -UTILS_EXPORT celix_status_t linkedList_create(linked_list_pt *list); +UTILS_EXPORT celix_status_t linkedList_create(linked_list_pt *list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT celix_status_t linkedList_destroy(linked_list_pt list); +UTILS_EXPORT celix_status_t linkedList_destroy(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT celix_status_t linkedList_clone(linked_list_pt list, linked_list_pt *clone); +UTILS_EXPORT celix_status_t linkedList_clone(linked_list_pt list, linked_list_pt *clone) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_getFirst(linked_list_pt list); +UTILS_EXPORT void *linkedList_getFirst(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_getLast(linked_list_pt list); +UTILS_EXPORT void *linkedList_getLast(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_removeFirst(linked_list_pt list); +UTILS_EXPORT void *linkedList_removeFirst(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_removeLast(linked_list_pt list); +UTILS_EXPORT void *linkedList_removeLast(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void linkedList_addFirst(linked_list_pt list, void *element); +UTILS_EXPORT void linkedList_addFirst(linked_list_pt list, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void linkedList_addLast(linked_list_pt list, void *element); +UTILS_EXPORT void linkedList_addLast(linked_list_pt list, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT bool linkedList_contains(linked_list_pt list, void *element); +UTILS_EXPORT bool linkedList_contains(linked_list_pt list, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT int linkedList_size(linked_list_pt list); +UTILS_EXPORT int linkedList_size(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT bool linkedList_isEmpty(linked_list_pt list); +UTILS_EXPORT bool linkedList_isEmpty(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT bool linkedList_addElement(linked_list_pt list, void *element); +UTILS_EXPORT bool linkedList_addElement(linked_list_pt list, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT bool linkedList_removeElement(linked_list_pt list, void *element); +UTILS_EXPORT bool linkedList_removeElement(linked_list_pt list, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void linkedList_clear(linked_list_pt list); +UTILS_EXPORT void linkedList_clear(linked_list_pt list) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_get(linked_list_pt list, int index); +UTILS_EXPORT void *linkedList_get(linked_list_pt list, int index) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_set(linked_list_pt list, int index, void *element); +UTILS_EXPORT void *linkedList_set(linked_list_pt list, int index, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void linkedList_addIndex(linked_list_pt list, int index, void *element); +UTILS_EXPORT void linkedList_addIndex(linked_list_pt list, int index, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_removeIndex(linked_list_pt list, int index); +UTILS_EXPORT void *linkedList_removeIndex(linked_list_pt list, int index) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT linked_list_entry_pt linkedList_entry(linked_list_pt list, int index); +UTILS_EXPORT linked_list_entry_pt linkedList_entry(linked_list_pt list, int index) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT int linkedList_indexOf(linked_list_pt list, void *element); +UTILS_EXPORT int linkedList_indexOf(linked_list_pt list, void *element) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT linked_list_entry_pt linkedList_addBefore(linked_list_pt list, void *element, linked_list_entry_pt entry); +UTILS_EXPORT linked_list_entry_pt linkedList_addBefore(linked_list_pt list, void *element, linked_list_entry_pt entry) CELIX_DEPRECATED_ATTR; -UTILS_EXPORT void *linkedList_removeEntry(linked_list_pt list, linked_list_entry_pt entry); +UTILS_EXPORT void *linkedList_removeEntry(linked_list_pt list, linked_list_entry_pt entry) CELIX_DEPRECATED_ATTR; #ifdef __cplusplus }
