Skip to content
Permalink
Browse files
fix rsalist race
  • Loading branch information
xuzhenbao committed Apr 11, 2022
1 parent 9cf8bc3 commit e913672af59ce570b6f64b9d5cbbdd839bc37ac1
Showing 1 changed file with 37 additions and 34 deletions.
@@ -209,7 +209,6 @@ celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt unus

celixThreadMutex_lock(&manager->rsaListLock);
arrayList_add(manager->rsaList, rsa);
celixThreadMutex_unlock(&manager->rsaListLock);

// add already imported services to new rsa
celixThreadMutex_lock(&manager->importedServicesLock);
@@ -269,6 +268,9 @@ celix_status_t topologyManager_rsaAdded(void * handle, service_reference_pt unus

hashMapIterator_destroy(exportedServicesIterator);
celixThreadMutex_unlock(&manager->exportedServicesLock);

celixThreadMutex_unlock(&manager->rsaListLock);

return CELIX_SUCCESS;
}

@@ -285,6 +287,8 @@ celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt re
topology_manager_pt manager = (topology_manager_pt) handle;
remote_service_admin_service_t *rsa = (remote_service_admin_service_t *) service;

celixThreadMutex_lock(&manager->rsaListLock);

if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
hash_map_iterator_pt iter = hashMapIterator_create(manager->exportedServices);

@@ -350,10 +354,8 @@ celix_status_t topologyManager_rsaRemoved(void * handle, service_reference_pt re
celixThreadMutex_unlock(&manager->importedServicesLock);
}

if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
arrayList_removeElement(manager->rsaList, rsa);
celixThreadMutex_unlock(&manager->rsaListLock);
}
arrayList_removeElement(manager->rsaList, rsa);
celixThreadMutex_unlock(&manager->rsaListLock);

celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_INFO, "TOPOLOGY_MANAGER: Removed RSA");

@@ -477,33 +479,32 @@ celix_status_t topologyManager_addImportedService(void *handle, endpoint_descrip

celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_INFO, "TOPOLOGY_MANAGER: Add imported service (%s; %s).", endpoint->service, endpoint->id);

celixThreadMutex_lock(&manager->rsaListLock);

if (celixThreadMutex_lock(&manager->importedServicesLock) == CELIX_SUCCESS) {

hash_map_pt imports = hashMap_create(NULL, NULL, NULL, NULL);
hashMap_put(manager->importedServices, endpoint, imports);

if (scope_allowImport(manager->scope, endpoint)) {
if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
int size = arrayList_size(manager->rsaList);
int size = arrayList_size(manager->rsaList);

for (int iter = 0; iter < size; iter++) {
import_registration_t *import = NULL;
remote_service_admin_service_t *rsa = arrayList_get(manager->rsaList, iter);
celix_status_t substatus = rsa->importService(rsa->admin, endpoint, &import);
if (substatus == CELIX_SUCCESS) {
hashMap_put(imports, rsa, import);
} else {
status = substatus;
}
for (int iter = 0; iter < size; iter++) {
import_registration_t *import = NULL;
remote_service_admin_service_t *rsa = arrayList_get(manager->rsaList, iter);
celix_status_t substatus = rsa->importService(rsa->admin, endpoint, &import);
if (substatus == CELIX_SUCCESS) {
hashMap_put(imports, rsa, import);
} else {
status = substatus;
}
celixThreadMutex_unlock(&manager->rsaListLock);
}

}

celixThreadMutex_unlock(&manager->importedServicesLock);
}

celixThreadMutex_unlock(&manager->rsaListLock);

return status;
}
@@ -563,36 +564,38 @@ celix_status_t topologyManager_addExportedService(void * handle, service_referen

celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_INFO, "TOPOLOGY_MANAGER: Add exported service (%li).", serviceId);

celixThreadMutex_lock(&manager->rsaListLock);

if (celixThreadMutex_lock(&manager->exportedServicesLock) == CELIX_SUCCESS) {
scope_getExportProperties(manager->scope, reference, &serviceProperties);
hash_map_pt exports = hashMap_create(NULL, NULL, NULL, NULL);
hashMap_put(manager->exportedServices, reference, exports);

if (celixThreadMutex_lock(&manager->rsaListLock) == CELIX_SUCCESS) {
int size = arrayList_size(manager->rsaList);
int size = arrayList_size(manager->rsaList);

if (size == 0) {
celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_WARNING, "TOPOLOGY_MANAGER: No RSA available yet.");
}
if (size == 0) {
celix_logHelper_log(manager->loghelper, CELIX_LOG_LEVEL_WARNING, "TOPOLOGY_MANAGER: No RSA available yet.");
}

for (int iter = 0; iter < size; iter++) {
remote_service_admin_service_t *rsa = arrayList_get(manager->rsaList, iter);
for (int iter = 0; iter < size; iter++) {
remote_service_admin_service_t *rsa = arrayList_get(manager->rsaList, iter);

array_list_pt endpoints = NULL;
celix_status_t substatus = rsa->exportService(rsa->admin, serviceIdStr, serviceProperties, &endpoints);
array_list_pt endpoints = NULL;
celix_status_t substatus = rsa->exportService(rsa->admin, serviceIdStr, serviceProperties, &endpoints);

if (substatus == CELIX_SUCCESS) {
hashMap_put(exports, rsa, endpoints);
topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
} else {
status = substatus;
}
if (substatus == CELIX_SUCCESS) {
hashMap_put(exports, rsa, endpoints);
topologyManager_notifyListenersEndpointAdded(manager, rsa, endpoints);
} else {
status = substatus;
}
celixThreadMutex_unlock(&manager->rsaListLock);
}

celixThreadMutex_unlock(&manager->exportedServicesLock);
}

celixThreadMutex_unlock(&manager->rsaListLock);

return status;
}

0 comments on commit e913672

Please sign in to comment.