Skip to content
Permalink
Browse files
Use reference counting to protect against concurrently unregistering …
…the same serviceId multiple times.

Reference counting together with atomic compare-and-swap make celix_serviceRegistry_unregisterService MT-safe.
  • Loading branch information
PengZheng committed Feb 26, 2022
1 parent 98fddd5 commit f2a4491d3789445bfe8670083ae7f25ae5824e15
Showing 1 changed file with 2 additions and 0 deletions.
@@ -1202,6 +1202,7 @@ void celix_serviceRegistry_unregisterService(celix_service_registry_t* registry,
service_registration_t *entry = celix_arrayList_get(registrations, i);
if (serviceRegistration_getServiceId(entry) == serviceId) {
reg = entry;
serviceRegistration_retain(reg); // protect against concurrently unregistering the same serviceId multiple times
break;
}
}
@@ -1210,6 +1211,7 @@ void celix_serviceRegistry_unregisterService(celix_service_registry_t* registry,

if (reg != NULL) {
serviceRegistration_unregister(reg);
serviceRegistration_release(reg);
} else {
fw_log(registry->framework->logger, CELIX_LOG_LEVEL_ERROR, "Cannot unregister service for service id %li. This id is not present or owned by the provided bundle (bnd id %li)", serviceId, celix_bundle_getId(bnd));
}

0 comments on commit f2a4491

Please sign in to comment.