Skip to content

Commit

Permalink
CELIX-351: Adds mutex usage to shell_tui to protect services changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pnoltes committed Feb 11, 2016
1 parent 58f521f commit 9434821
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion dependency_manager/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions shell_tui/private/include/shell_tui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 8 additions & 1 deletion shell_tui/private/src/activator.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions shell_tui/private/src/shell_tui.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

Expand Down

0 comments on commit 9434821

Please sign in to comment.