You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by ej...@apache.org on 2016/08/19 13:18:45 UTC
[3/6] celix git commit: event publisher now thread safe. still 1
dangling service ref. now make event handler thread safe
event publisher now thread safe. still 1 dangling service ref. now make event handler thread safe
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/7291bef8
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/7291bef8
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/7291bef8
Branch: refs/heads/feature/event_admin
Commit: 7291bef802417bd7e5f7d1793b30198c5670a1d1
Parents: f358e33
Author: Erik Jansman <ej...@apache.org>
Authored: Wed Aug 17 15:36:47 2016 +0200
Committer: Erik Jansman <ej...@apache.org>
Committed: Wed Aug 17 15:36:47 2016 +0200
----------------------------------------------------------------------
event_admin/CMakeLists.txt | 1 +
.../private/include/event_publisher_impl.h | 1 +
.../private/src/event_publisher_impl.c | 34 +++++++-------------
3 files changed, 14 insertions(+), 22 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/7291bef8/event_admin/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/event_admin/CMakeLists.txt b/event_admin/CMakeLists.txt
index 38e0d08..44d7169 100644
--- a/event_admin/CMakeLists.txt
+++ b/event_admin/CMakeLists.txt
@@ -35,4 +35,5 @@ if(EVENT_ADMIN)
NAME "event_publisher_consumer"
GROUP "event_publisher"
BUNDLES event_admin event_publisher event_handler shell_tui shell log_writer log_service )
+ #BUNDLES event_publisher shell_tui shell log_writer log_service )
endif(EVENT_ADMIN)
http://git-wip-us.apache.org/repos/asf/celix/blob/7291bef8/event_admin/event_publisher/private/include/event_publisher_impl.h
----------------------------------------------------------------------
diff --git a/event_admin/event_publisher/private/include/event_publisher_impl.h b/event_admin/event_publisher/private/include/event_publisher_impl.h
index 5d6ba5b..ce38aa5 100644
--- a/event_admin/event_publisher/private/include/event_publisher_impl.h
+++ b/event_admin/event_publisher/private/include/event_publisher_impl.h
@@ -47,6 +47,7 @@ struct event_publisher {
bool running;
bool eventAdminAdded;
celix_thread_t sender;
+ celix_thread_mutex_t *eventAdminAvailility;
bundle_context_pt context;
log_helper_pt loghelper;
};
http://git-wip-us.apache.org/repos/asf/celix/blob/7291bef8/event_admin/event_publisher/private/src/event_publisher_impl.c
----------------------------------------------------------------------
diff --git a/event_admin/event_publisher/private/src/event_publisher_impl.c b/event_admin/event_publisher/private/src/event_publisher_impl.c
index 9a43b80..49583b6 100644
--- a/event_admin/event_publisher/private/src/event_publisher_impl.c
+++ b/event_admin/event_publisher/private/src/event_publisher_impl.c
@@ -43,6 +43,7 @@ celix_status_t eventPublisherCreate(bundle_context_pt context, event_publisher_p
(*event_publisher)->running = false;
(*event_publisher)->context = context;
(*event_publisher)->sender = celix_thread_default;
+ (*event_publisher)->eventAdminAvailility = calloc(1, sizeof(celix_thread_mutex_t));
logHelper_create(context, &(*event_publisher)->loghelper);
}
return status;
@@ -53,13 +54,14 @@ celix_status_t eventPublisherStart(event_publisher_pt *event_publisher) {
(*event_publisher)->running = true;
logHelper_start((*event_publisher)->loghelper);
status = celixThread_create(&(*event_publisher)->sender, NULL, produceEvents, &(*event_publisher));
+ celixThreadMutex_create((*event_publisher)->eventAdminAvailility,NULL);
if(status != CELIX_SUCCESS)
{
printf("failed to create thread\n");
}
else
{
- printf("trhead created \n");
+ printf("thread created \n");
}
return status;
}
@@ -80,39 +82,24 @@ celix_status_t eventPublisherDestroy(event_publisher_pt *event_publisher)
}
void *produceEvents(void *handle) {
- int i =0;
event_publisher_pt *event_publisher = handle;
while ((*event_publisher)->running ) {
- if((*event_publisher)->eventAdminAdded) {
+ if((*event_publisher)->eventAdminAdded && celixThreadMutex_tryLock((*event_publisher)->eventAdminAvailility) == 0) {
event_admin_service_pt *event_admin_service = &(*event_publisher)->event_admin_service;
event_admin_pt event_admin = (*event_admin_service)->eventAdmin;
if (event_admin_service != NULL) {
event_pt event;
properties_pt props = properties_create();
- properties_set(props, "This is a key", "this is a value");
- printf("create event\n");
+ properties_set(props, "Error ", "No Error, Just testing");
(*event_admin_service)->createEvent(event_admin, "log/error/eventpublishers/event", props, &event);
- printf("post event\n");
(*event_admin_service)->postEvent(event_admin, event);
- printf("send event\n");
(*event_admin_service)->sendEvent(event_admin, event);
-
- } else {
- printf("could not send event\n");
}
+ celixThreadMutex_unlock((*event_publisher)->eventAdminAvailility);
}
- else
- {
- printf("No event admin\n");
- }
- for (i=0;i<10000000; i++){
- continue;
- }
+ usleep(1*10000);
}
- printf("end of thread\n");
-
-
return CELIX_SUCCESS;
}
@@ -128,9 +115,11 @@ celix_status_t eventPublisherAddingService(void * handle, service_reference_pt r
celix_status_t eventPublisherAddedService(void * handle, service_reference_pt ref, void * service) {
event_publisher_pt data = (event_publisher_pt) handle;
logHelper_log(data->loghelper, OSGI_LOGSERVICE_DEBUG, "[PUB] Event admin added.");
- printf(" added event admin");
+ printf(" added event admin\n");
+ celixThreadMutex_lock(data->eventAdminAvailility);
data->event_admin_service = (event_admin_service_pt) service;
data->eventAdminAdded = true;
+ celixThreadMutex_unlock(data->eventAdminAvailility);
return CELIX_SUCCESS;
}
@@ -143,9 +132,10 @@ celix_status_t eventPublisherModifiedService(void * handle, service_reference_pt
celix_status_t eventPublisherRemovedService(void * handle, service_reference_pt ref, void * service) {
event_publisher_pt data = (event_publisher_pt) handle;
logHelper_log(data->loghelper, OSGI_LOGSERVICE_DEBUG, "[PUB] Event admin removed.");
-
+ celixThreadMutex_lock(data->eventAdminAvailility);
data->event_admin_service = NULL;
data->eventAdminAdded = false;
+ celixThreadMutex_unlock(data->eventAdminAvailility);
return CELIX_SUCCESS;
}