You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2015/12/03 20:54:44 UTC
[2/2] celix git commit: CELIX-317: Simplify dm_example. Phase3 now
uses suspend strategy and so all locking code is removed (cleaner example).
CELIX-317: Simplify dm_example. Phase3 now uses suspend strategy and so all locking code is removed (cleaner example).
Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/51cd8f42
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/51cd8f42
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/51cd8f42
Branch: refs/heads/develop
Commit: 51cd8f4261ded8c1e52b393be017ce8eb22fb87e
Parents: 695b70d
Author: Pepijn Noltes <pe...@gmail.com>
Authored: Thu Dec 3 20:54:25 2015 +0100
Committer: Pepijn Noltes <pe...@gmail.com>
Committed: Thu Dec 3 20:54:25 2015 +0100
----------------------------------------------------------------------
.../phase3/private/include/phase3_cmp.h | 2 +-
.../phase3/private/src/phase3_activator.c | 7 +---
.../dm_example/phase3/private/src/phase3_cmp.c | 43 +-------------------
3 files changed, 5 insertions(+), 47 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/celix/blob/51cd8f42/examples/dm_example/phase3/private/include/phase3_cmp.h
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/include/phase3_cmp.h b/examples/dm_example/phase3/private/include/phase3_cmp.h
index 3e4f087..64c4137 100644
--- a/examples/dm_example/phase3/private/include/phase3_cmp.h
+++ b/examples/dm_example/phase3/private/include/phase3_cmp.h
@@ -31,7 +31,7 @@
typedef struct phase3_cmp_struct phase3_cmp_t;
-phase3_cmp_t *phase3_create(bool lockStrategy);
+phase3_cmp_t *phase3_create();
int phase3_init(phase3_cmp_t *cmp);
int phase3_start(phase3_cmp_t *cmp);
int phase3_stop(phase3_cmp_t *cmp);
http://git-wip-us.apache.org/repos/asf/celix/blob/51cd8f42/examples/dm_example/phase3/private/src/phase3_activator.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_activator.c b/examples/dm_example/phase3/private/src/phase3_activator.c
index bc6a4f7..94f1433 100644
--- a/examples/dm_example/phase3/private/src/phase3_activator.c
+++ b/examples/dm_example/phase3/private/src/phase3_activator.c
@@ -47,10 +47,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
struct phase3_activator_struct *act = (struct phase3_activator_struct *)userData;
- dm_service_dependency_strategy_t strategy = DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND;
- bool lockStrategy = (strategy==DM_SERVICE_DEPENDENCY_STRATEGY_LOCKING);
-
- act->phase3Cmp = phase3_create(lockStrategy);
+ act->phase3Cmp = phase3_create();
if (act->phase3Cmp != NULL) {
dm_component_pt cmp;
@@ -61,7 +58,7 @@ celix_status_t dm_init(void * userData, bundle_context_pt context, dm_dependency
dm_service_dependency_pt dep;
serviceDependency_create(&dep);
serviceDependency_setService(dep, PHASE2_NAME, NULL);
- serviceDependency_setStrategy(dep, strategy);
+ serviceDependency_setStrategy(dep, DM_SERVICE_DEPENDENCY_STRATEGY_SUSPEND);
serviceDependency_setCallbacksSafe(dep, phase3_cmp_t *, phase2_t *, NULL, phase3_addPhase2, NULL, phase3_removePhase2, NULL);
serviceDependency_setRequired(dep, true);
component_addServiceDependency(cmp, dep);
http://git-wip-us.apache.org/repos/asf/celix/blob/51cd8f42/examples/dm_example/phase3/private/src/phase3_cmp.c
----------------------------------------------------------------------
diff --git a/examples/dm_example/phase3/private/src/phase3_cmp.c b/examples/dm_example/phase3/private/src/phase3_cmp.c
index a38d77d..db01ad3 100644
--- a/examples/dm_example/phase3/private/src/phase3_cmp.c
+++ b/examples/dm_example/phase3/private/src/phase3_cmp.c
@@ -38,21 +38,17 @@ struct phase3_cmp_struct {
celix_thread_t thread;
bool running;
double currentValue;
- celix_thread_mutex_t mutex;
array_list_pt phase2Services; //phase2_t *
- bool lockStrategy;
};
static void *phase3_thread(void *data);
-phase3_cmp_t *phase3_create(bool lockStrategy) {
+phase3_cmp_t *phase3_create() {
phase3_cmp_t *cmp = calloc(1, sizeof(*cmp));
if (cmp != NULL) {
cmp->currentValue = 0.0;
cmp->running = false;
- celixThreadMutex_create(&cmp->mutex, NULL);
arrayList_create(&cmp->phase2Services);
- cmp->lockStrategy = lockStrategy;
}
return cmp;
}
@@ -83,44 +79,18 @@ int phase3_deinit(phase3_cmp_t *cmp) {
}
void phase3_destroy(phase3_cmp_t *cmp) {
- if(cmp->lockStrategy){
- celixThreadMutex_lock(&cmp->mutex);
- }
-
arrayList_destroy(cmp->phase2Services);
-
- if(cmp->lockStrategy){
- celixThreadMutex_unlock(&cmp->mutex);
- }
-
- celixThreadMutex_destroy(&cmp->mutex);
free(cmp);
printf("destroy phase3\n");
}
int phase3_addPhase2(phase3_cmp_t *cmp, phase2_t *phase2) {
- if(cmp->lockStrategy){
- celixThreadMutex_lock(&cmp->mutex);
- }
-
arrayList_add(cmp->phase2Services, phase2);
-
- if(cmp->lockStrategy){
- celixThreadMutex_unlock(&cmp->mutex);
- }
return 0;
}
int phase3_removePhase2(phase3_cmp_t *cmp, phase2_t *phase2) {
- if(cmp->lockStrategy){
- celixThreadMutex_lock(&cmp->mutex);
- }
-
arrayList_removeElement(cmp->phase2Services, phase2);
-
- if(cmp->lockStrategy){
- celixThreadMutex_unlock(&cmp->mutex);
- }
return 0;
}
@@ -132,24 +102,15 @@ static void *phase3_thread(void *data) {
double value;
while (cmp->running) {
- if(cmp->lockStrategy){
- celixThreadMutex_lock(&cmp->mutex);
- }
-
size = arrayList_size(cmp->phase2Services);
for (i = 0; i < size; i += 1) {
phase2_t *serv = arrayList_get(cmp->phase2Services, i);
serv->getData(serv->handle, &value);
printf("PHASE3: Data from %p is %f\n", serv, value);
}
-
- if(cmp->lockStrategy){
- celixThreadMutex_unlock(&cmp->mutex);
- }
-
usleep(SLEEPTIME);
}
celixThread_exit(NULL);
return NULL;
-}
\ No newline at end of file
+}