celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abroekh...@apache.org
Subject svn commit: r1620899 - /celix/trunk/framework/private/src/service_registry.c
Date Wed, 27 Aug 2014 13:53:41 GMT
Author: abroekhuis
Date: Wed Aug 27 13:53:41 2014
New Revision: 1620899

URL: http://svn.apache.org/r1620899
Log:
Readded incorrecty removed line for mutex creation.

Modified:
    celix/trunk/framework/private/src/service_registry.c

Modified: celix/trunk/framework/private/src/service_registry.c
URL: http://svn.apache.org/viewvc/celix/trunk/framework/private/src/service_registry.c?rev=1620899&r1=1620898&r2=1620899&view=diff
==============================================================================
--- celix/trunk/framework/private/src/service_registry.c (original)
+++ celix/trunk/framework/private/src/service_registry.c Wed Aug 27 13:53:41 2014
@@ -64,6 +64,7 @@ celix_status_t serviceRegistry_create(fr
 
 		status = celixThreadMutexAttr_create(&(*registry)->mutexAttr);
 		status = CELIX_DO_IF(status, celixThreadMutexAttr_settype(&(*registry)->mutexAttr,
CELIX_THREAD_MUTEX_RECURSIVE));
+		status = CELIX_DO_IF(status, celixThreadMutex_create(&(*registry)->mutex, &(*registry)->mutexAttr));
 		status = CELIX_DO_IF(status, celixThreadMutex_create(&(*registry)->referencesMapMutex,
NULL));
 	}
 
@@ -86,6 +87,7 @@ celix_status_t serviceRegistry_destroy(s
     registry->serviceChanged = NULL;
     registry->serviceReferences = NULL;
     registry->serviceRegistrations = NULL;
+    free(registry);
 
     return CELIX_SUCCESS;
 }
@@ -149,6 +151,7 @@ static celix_status_t serviceRegistry_fl
 celix_status_t serviceRegistry_getRegisteredServices(service_registry_pt registry, bundle_pt
bundle, array_list_pt *services) {
 	celix_status_t status = CELIX_SUCCESS;
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	array_list_pt regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
 	if (regs != NULL) {
@@ -166,6 +169,7 @@ celix_status_t serviceRegistry_getRegist
 			}
 		}
 	}
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	framework_logIfError(logger, status, NULL, "Cannot get registered services");
@@ -183,6 +187,7 @@ celix_status_t serviceRegistry_registerS
 
 celix_status_t serviceRegistry_registerServiceInternal(service_registry_pt registry, bundle_pt
bundle, char * serviceName, void * serviceObject, properties_pt dictionary, bool isFactory,
service_registration_pt *registration) {
 	array_list_pt regs;
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 
 	if (isFactory) {
@@ -201,6 +206,7 @@ celix_status_t serviceRegistry_registerS
 	arrayList_add(regs, *registration);
 	hashMap_put(registry->serviceRegistrations, bundle, regs);
 
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	if (registry->serviceChanged != NULL) {
@@ -221,6 +227,7 @@ celix_status_t serviceRegistry_unregiste
 	array_list_pt regs;
 	array_list_pt references = NULL;
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 
 	serviceRegistry_removeHook(registry, registration);
@@ -231,12 +238,14 @@ celix_status_t serviceRegistry_unregiste
 		hashMap_put(registry->serviceRegistrations, bundle, regs);
 	}
 
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	if (registry->serviceChanged != NULL) {
 		registry->serviceChanged(registry->framework, OSGI_FRAMEWORK_SERVICE_EVENT_UNREGISTERING,
registration, NULL);
 	}
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	// unget service
 
@@ -258,11 +267,14 @@ celix_status_t serviceRegistry_unregiste
 
 		serviceReference_invalidate(reference);
 	}
+	arrayList_destroy(references);
+
 	//TODO not needed, the registration is destroyed, any reference to the registration is invalid
and will result in a segfault
 	serviceRegistration_invalidate(registration);
 
 	serviceRegistration_destroy(registration);
 
+	printf("Reg Unock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	return CELIX_SUCCESS;
@@ -271,8 +283,10 @@ celix_status_t serviceRegistry_unregiste
 celix_status_t serviceRegistry_unregisterServices(service_registry_pt registry, bundle_pt
bundle) {
 	array_list_pt regs = NULL;
 	unsigned int i;
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	regs = (array_list_pt) hashMap_get(registry->serviceRegistrations, bundle);
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 	
 	for (i = 0; (regs != NULL) && i < arrayList_size(regs); i++) {
@@ -290,8 +304,10 @@ celix_status_t serviceRegistry_unregiste
 		removed = NULL;
 	}
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	hashMap_remove(registry->serviceRegistrations, bundle);
+	printf("Reg Unock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	return CELIX_SUCCESS;
@@ -307,6 +323,7 @@ celix_status_t serviceRegistry_createSer
 	serviceReference_create(bundle, registration, reference);
 
 	// Lock
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->referencesMapMutex);
 	array_list_pt references = hashMap_get(registry->serviceReferences, owner);
 	if (references == NULL) {
@@ -316,6 +333,7 @@ celix_status_t serviceRegistry_createSer
 	hashMap_put(registry->serviceReferences, owner, references);
 
 	// Unlock
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->referencesMapMutex);
 
 	framework_logIfError(logger, status, NULL, "Cannot create service reference");
@@ -350,6 +368,9 @@ celix_status_t serviceRegistry_getServic
             }
         }
     }
+    hashMapIterator_destroy(iterator);
+    hashMapValues_destroy(referenceValues);
+
     celixThreadMutex_unlock(&registry->referencesMapMutex);
 
     return status;
@@ -361,6 +382,7 @@ celix_status_t serviceRegistry_getServic
 	hash_map_iterator_pt iterator;
 	arrayList_create(references);
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	registrations = hashMapValues_create(registry->serviceRegistrations);
 	iterator = hashMapValues_iterator(registrations);
@@ -403,6 +425,7 @@ celix_status_t serviceRegistry_getServic
 	}
 	hashMapIterator_destroy(iterator);
 	hashMapValues_destroy(registrations);
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	framework_logIfError(logger, status, NULL, "Cannot get service references");
@@ -453,12 +476,14 @@ celix_status_t serviceRegistry_ungetServ
             service_reference_pt reference = arrayList_get(referencesClone, refIdx);
             serviceRegistry_ungetServiceReference(registry, owner, reference);
         }
+        arrayList_destroy(referencesClone);
     }
 
     return status;
 }
 
 celix_status_t serviceRegistry_getServicesInUse(service_registry_pt registry, bundle_pt bundle,
array_list_pt *services) {
+    printf("Reg Lock\n");
     celixThreadMutex_lock(&registry->mutex);
 	array_list_pt usages = hashMap_get(registry->inUseMap, bundle);
 	if (usages != NULL) {
@@ -470,6 +495,7 @@ celix_status_t serviceRegistry_getServic
 			arrayList_add(*services, usage->reference);
 		}
 	}
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 	return CELIX_SUCCESS;
 }
@@ -481,6 +507,7 @@ celix_status_t serviceRegistry_getServic
 	usage_count_pt usage = NULL;
 	serviceReference_getServiceRegistration(reference, &registration);
 	
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 
 	if (serviceRegistration_isValid(registration)) {
@@ -491,17 +518,20 @@ celix_status_t serviceRegistry_getServic
 		usage->count++;
 		*service = usage->service;
 	}
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	if ((usage != NULL) && (*service == NULL)) {
 		serviceRegistration_getService(registration, bundle, service);
 	}
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	if ((!serviceRegistration_isValid(registration)) || (*service == NULL)) {
 		serviceRegistry_flushUsageCount(registry, bundle, reference);
 	} else {
 		usage->service = *service;
 	}
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	return CELIX_SUCCESS;
@@ -513,10 +543,12 @@ celix_status_t serviceRegistry_ungetServ
 	usage_count_pt usage = NULL;
 	serviceReference_getServiceRegistration(reference, &registration);
 	
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 
 	status = serviceRegistry_getUsageCount(registry, bundle, reference, &usage);
 	if (usage == NULL) {
+	    printf("Reg Unlock\n");
 		celixThreadMutex_unlock(&registry->mutex);
 		*result = false;
 		return CELIX_SUCCESS;
@@ -529,6 +561,7 @@ celix_status_t serviceRegistry_ungetServ
 		serviceRegistry_flushUsageCount(registry, bundle, reference);
 	}
 
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	*result = true;
@@ -541,8 +574,10 @@ void serviceRegistry_ungetServices(servi
 	array_list_pt usages;
 	unsigned int i;
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	usages = hashMap_get(registry->inUseMap, bundle);
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 
 	if (usages == NULL || arrayList_isEmpty(usages)) {
@@ -569,6 +604,7 @@ array_list_pt serviceRegistry_getUsingBu
 	hash_map_iterator_pt iter;
 	arrayList_create(&bundles);
 
+	printf("Reg Lock\n");
 	celixThreadMutex_lock(&registry->mutex);
 	iter = hashMapIterator_create(registry->inUseMap);
 	while (hashMapIterator_hasNext(iter)) {
@@ -586,6 +622,7 @@ array_list_pt serviceRegistry_getUsingBu
 		}
 	}
 	hashMapIterator_destroy(iter);
+	printf("Reg Unlock\n");
 	celixThreadMutex_unlock(&registry->mutex);
 	return bundles;
 }



Mime
View raw message