CELIX-351: Adds mutex usage to shell_tui to protect services changes
Project: http://git-wip-us.apache.org/repos/asf/celix/repo Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/94348219 Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/94348219 Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/94348219 Branch: refs/heads/release/celix-2.0.0 Commit: 94348219b56d641bcbe9547d40a71962521c2afa Parents: 58f521f Author: Pepijn Noltes <[email protected]> Authored: Thu Feb 11 20:35:02 2016 +0100 Committer: Pepijn Noltes <[email protected]> Committed: Thu Feb 11 20:35:02 2016 +0100 ---------------------------------------------------------------------- dependency_manager/CMakeLists.txt | 6 +++++- shell_tui/private/include/shell_tui.h | 1 + shell_tui/private/src/activator.c | 9 ++++++++- shell_tui/private/src/shell_tui.c | 2 ++ 4 files changed, 16 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/celix/blob/94348219/dependency_manager/CMakeLists.txt ---------------------------------------------------------------------- diff --git a/dependency_manager/CMakeLists.txt b/dependency_manager/CMakeLists.txt index 8c1f74f..5ec35ec 100644 --- a/dependency_manager/CMakeLists.txt +++ b/dependency_manager/CMakeLists.txt @@ -57,7 +57,11 @@ if (DEPENDENCY_MANAGER) private/src/dm_dependency_manager_impl ) set_target_properties(dependency_manager_so PROPERTIES SOVERSION 1) - target_link_libraries(dependency_manager_so celix_framework) + if (APPLE) + target_link_libraries(dependency_manager_so celix_framework "-undefined dynamic_lookup") + else() + target_link_libraries(dependency_manager_so celix_framework) + endif() include_directories("public/include") include_directories("private/include") http://git-wip-us.apache.org/repos/asf/celix/blob/94348219/shell_tui/private/include/shell_tui.h ---------------------------------------------------------------------- diff --git a/shell_tui/private/include/shell_tui.h b/shell_tui/private/include/shell_tui.h index 2d7c251..29f5eda 100644 --- a/shell_tui/private/include/shell_tui.h +++ b/shell_tui/private/include/shell_tui.h @@ -41,6 +41,7 @@ struct shellTuiActivator { service_tracker_pt tracker; bool running; celix_thread_t runnable; + celix_thread_mutex_t mutex; }; typedef struct shellTuiActivator * shell_tui_activator_pt; http://git-wip-us.apache.org/repos/asf/celix/blob/94348219/shell_tui/private/src/activator.c ---------------------------------------------------------------------- diff --git a/shell_tui/private/src/activator.c b/shell_tui/private/src/activator.c index 1759e38..ec28088 100644 --- a/shell_tui/private/src/activator.c +++ b/shell_tui/private/src/activator.c @@ -35,13 +35,19 @@ static celix_status_t activator_addShellService(void *handle, service_reference_pt ref, void *svc) { shell_tui_activator_pt act = (shell_tui_activator_pt) handle; + celixThreadMutex_lock(&act->mutex); act->shell = svc; + celixThreadMutex_unlock(&act->mutex); return CELIX_SUCCESS; } static celix_status_t activator_removeShellService(void *handle, service_reference_pt ref, void *svc) { shell_tui_activator_pt act = (shell_tui_activator_pt) handle; - act->shell = svc; + celixThreadMutex_lock(&act->mutex); + if (act->shell == svc) { + act->shell = NULL; + } + celixThreadMutex_unlock(&act->mutex); return CELIX_SUCCESS; } @@ -52,6 +58,7 @@ celix_status_t bundleActivator_create(bundle_context_pt context, void **userData if (activator) { activator->shell = NULL; + celixThreadMutex_create(&activator->mutex, NULL); (*userData) = activator; } else { http://git-wip-us.apache.org/repos/asf/celix/blob/94348219/shell_tui/private/src/shell_tui.c ---------------------------------------------------------------------- diff --git a/shell_tui/private/src/shell_tui.c b/shell_tui/private/src/shell_tui.c index fbff74e..b659188 100644 --- a/shell_tui/private/src/shell_tui.c +++ b/shell_tui/private/src/shell_tui.c @@ -72,11 +72,13 @@ static void* shellTui_runnable(void *data) { continue; } + celixThreadMutex_lock(&act->mutex); if (act->shell != NULL) { act->shell->executeCommand(act->shell->shell, line, stdout, stderr); } else { fprintf(stderr, "Shell service not available\n"); } + celixThreadMutex_unlock(&act->mutex); } }
