celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [3/3] celix git commit: CELIX-272: Invoke service tracker callbacks outside the array_list lock.
Date Thu, 19 Nov 2015 15:37:36 GMT
CELIX-272: Invoke service tracker callbacks outside the array_list lock.


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/254d7bf1
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/254d7bf1
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/254d7bf1

Branch: refs/heads/develop
Commit: 254d7bf1fb5187f373711478718f9c7ac7938153
Parents: bd5a57c
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
Authored: Thu Nov 19 16:30:15 2015 +0100
Committer: Pepijn Noltes <pepijnnoltes@gmail.com>
Committed: Thu Nov 19 16:30:15 2015 +0100

----------------------------------------------------------------------
 framework/private/src/service_tracker.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/254d7bf1/framework/private/src/service_tracker.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_tracker.c b/framework/private/src/service_tracker.c
index 4256c52..7714139 100644
--- a/framework/private/src/service_tracker.c
+++ b/framework/private/src/service_tracker.c
@@ -275,8 +275,7 @@ static celix_status_t serviceTracker_track(service_tracker_pt tracker,
service_r
 	bool found = false;
 	unsigned int i;
 
-    celixThreadRwlock_writeLock(&tracker->lock);
-
+    celixThreadRwlock_readLock(&tracker->lock);
 	for (i = 0; i < arrayList_size(tracker->trackedServices); i++) {
 		bool equals = false;
 		tracked = (tracked_pt) arrayList_get(tracker->trackedServices, i);
@@ -289,6 +288,7 @@ static celix_status_t serviceTracker_track(service_tracker_pt tracker,
service_r
 			break;
 		}
 	}
+    celixThreadRwlock_unlock(&tracker->lock);
 
 	if (status == CELIX_SUCCESS && !found /*new*/) {
 		void * service = NULL;
@@ -299,15 +299,19 @@ static celix_status_t serviceTracker_track(service_tracker_pt tracker,
service_r
 				assert(reference != NULL);
 				tracked->reference = reference;
 				tracked->service = service;
-				arrayList_add(tracker->trackedServices, tracked);
                 serviceTracker_invokeAddService(tracker, reference, service);
+                celixThreadRwlock_writeLock(&tracker->lock);
+                arrayList_add(tracker->trackedServices, tracked);
+                celixThreadRwlock_unlock(&tracker->lock);
 			}
 		}
+
 	} else {
         status = serviceTracker_invokeModifiedService(tracker, reference, tracked->service);
 	}
 
-    celixThreadRwlock_unlock(&tracker->lock);
+
+
 
 	framework_logIfError(logger, status, NULL, "Cannot track reference");
 
@@ -387,13 +391,16 @@ static celix_status_t serviceTracker_untrack(service_tracker_pt tracker,
service
 		serviceReference_equals(reference, tracked->reference, &equals);
 		if (equals) {
 			arrayList_remove(tracker->trackedServices, i);
-            serviceTracker_invokeRemovingService(tracker, tracked->reference, tracked->service);
-			free(tracked);
             break;
 		}
 	}
     celixThreadRwlock_unlock(&tracker->lock);
 
+    if (tracked != NULL) {
+        serviceTracker_invokeRemovingService(tracker, tracked->reference, tracked->service);
+        free(tracked);
+    }
+
 	framework_logIfError(logger, status, NULL, "Cannot untrack reference");
 
 	return status;


Mime
View raw message