You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by bp...@apache.org on 2015/11/19 10:55:02 UTC

celix git commit: CELIX-280: fixed dataRace in serviceRegistry

Repository: celix
Updated Branches:
  refs/heads/develop c7609e328 -> 5d8af0aa5


CELIX-280: fixed dataRace in serviceRegistry


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

Branch: refs/heads/develop
Commit: 5d8af0aa522c59db2a263e22c34f6157385865a2
Parents: c7609e3
Author: Bjoern Petri <bp...@apache.org>
Authored: Thu Nov 19 10:53:43 2015 +0100
Committer: Bjoern Petri <bp...@apache.org>
Committed: Thu Nov 19 10:53:43 2015 +0100

----------------------------------------------------------------------
 framework/private/src/service_registry.c | 22 ++++++++++++++++++----
 1 file changed, 18 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/5d8af0aa/framework/private/src/service_registry.c
----------------------------------------------------------------------
diff --git a/framework/private/src/service_registry.c b/framework/private/src/service_registry.c
index d78da51..5823c26 100644
--- a/framework/private/src/service_registry.c
+++ b/framework/private/src/service_registry.c
@@ -234,12 +234,17 @@ celix_status_t serviceRegistry_unregisterService(service_registry_pt registry, b
 celix_status_t serviceRegistry_clearServiceRegistrations(service_registry_pt registry, bundle_pt bundle) {
     celix_status_t status = CELIX_SUCCESS;
     array_list_pt registrations = NULL;
+    bool registrationsLeft;
 
-	celixThreadRwlock_writeLock(&registry->lock);
-	registrations = hashMap_remove(registry->serviceRegistrations, bundle);
-	celixThreadRwlock_unlock(&registry->lock);
+    celixThreadRwlock_writeLock(&registry->lock);
+    registrations = hashMap_get(registry->serviceRegistrations, bundle);
+    registrationsLeft = (registrations != NULL);
+    if (registrationsLeft) {
+        registrationsLeft = (arrayList_size(registrations) > 0);
+    }
+    celixThreadRwlock_unlock(&registry->lock);
 
-    while (registrations != NULL && arrayList_size(registrations) > 0) {
+    while (registrationsLeft) {
         service_registration_pt reg = arrayList_get(registrations, 0);
 
         serviceRegistry_logWarningServiceRegistration(registry, reg);
@@ -250,6 +255,15 @@ celix_status_t serviceRegistry_clearServiceRegistrations(service_registry_pt reg
         else {
             arrayList_remove(registrations, 0);
         }
+
+        // not removed by last unregister call?
+        celixThreadRwlock_writeLock(&registry->lock);
+        registrations = hashMap_get(registry->serviceRegistrations, bundle);
+        registrationsLeft = (registrations != NULL);
+        if (registrationsLeft) {
+            registrationsLeft = (arrayList_size(registrations) > 0);
+        }
+        celixThreadRwlock_unlock(&registry->lock);
     }
 
     return status;