This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch feature/use_async_api_for_rsa
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/feature/use_async_api_for_rsa 
by this push:
     new 3a0d009  Updates rsa export/import_registration to use celix async api 
to prevent deadlocks
3a0d009 is described below

commit 3a0d009c0468dc3ca3ee63eba59ebbc501ef4c86
Author: Pepijn Noltes <[email protected]>
AuthorDate: Tue May 18 19:44:07 2021 +0200

    Updates rsa export/import_registration to use celix async api to prevent 
deadlocks
---
 .../include/import_registration.h                  |  1 -
 .../src/export_registration_dfi.c                  | 66 +++++++++-------------
 .../src/export_registration_dfi.h                  |  1 -
 .../src/import_registration_dfi.c                  | 50 ++++++++--------
 .../src/import_registration_dfi.h                  |  2 -
 .../src/remote_service_admin_dfi.c                 |  5 --
 6 files changed, 50 insertions(+), 75 deletions(-)

diff --git 
a/bundles/remote_services/deprecated_rsa_spi/include/import_registration.h 
b/bundles/remote_services/deprecated_rsa_spi/include/import_registration.h
index d10ae7c..c51eeea 100644
--- a/bundles/remote_services/deprecated_rsa_spi/include/import_registration.h
+++ b/bundles/remote_services/deprecated_rsa_spi/include/import_registration.h
@@ -28,7 +28,6 @@ typedef struct import_registration import_registration_t;
 
 typedef struct import_reference import_reference_t;
 
-celix_status_t importRegistration_close(import_registration_t *registration);
 celix_status_t importRegistration_getException(import_registration_t 
*registration);
 celix_status_t importRegistration_getImportReference(import_registration_t 
*registration, import_reference_t **reference);
 
diff --git 
a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
 
b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
index 4f933ac..7af2cd9 100644
--- 
a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
+++ 
b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.c
@@ -229,31 +229,37 @@ static celix_status_t 
exportRegistration_findAndParseInterfaceDescriptor(celix_l
     return CELIX_BUNDLE_EXCEPTION;
 }
 
+static void exportRegistration_destroyCallback(void* data) {
+    export_registration_t* reg = data;
+    if (reg->intf != NULL) {
+        dyn_interface_type *intf = reg->intf;
+        reg->intf = NULL;
+        dynInterface_destroy(intf);
+    }
+
+    if (reg->exportReference.endpoint != NULL) {
+        endpoint_description_t *ep = reg->exportReference.endpoint;
+        reg->exportReference.endpoint = NULL;
+        endpointDescription_destroy(ep);
+    }
+    if (reg->servId != NULL) {
+        free(reg->servId);
+    }
+    remoteInterceptorsHandler_destroy(reg->interceptorsHandler);
+    bundleContext_ungetServiceReference(reg->context, 
reg->exportReference.reference);
+
+    celixThreadMutex_destroy(&reg->mutex);
+    celixThreadCondition_destroy(&reg->cond);
+    free(reg);
+}
+
 void exportRegistration_destroy(export_registration_t *reg) {
     if (reg != NULL) {
-        if (reg->intf != NULL) {
-            dyn_interface_type *intf = reg->intf;
-            reg->intf = NULL;
-            dynInterface_destroy(intf);
-        }
-
-        if (reg->exportReference.endpoint != NULL) {
-            endpoint_description_t *ep = reg->exportReference.endpoint;
-            reg->exportReference.endpoint = NULL;
-            endpointDescription_destroy(ep);
-        }
         if (reg->trackerId >= 0) {
-            celix_bundleContext_stopTracker(reg->context, reg->trackerId);
-        }
-        if (reg->servId != NULL) {
-            free(reg->servId);
+            celix_bundleContext_stopTrackerAsync(reg->context, reg->trackerId, 
reg, exportRegistration_destroyCallback);
+        } else {
+            exportRegistration_destroyCallback(reg);
         }
-
-        remoteInterceptorsHandler_destroy(reg->interceptorsHandler);
-
-        celixThreadMutex_destroy(&reg->mutex);
-        celixThreadCondition_destroy(&reg->cond);
-        free(reg);
     }
 }
 
@@ -277,28 +283,12 @@ celix_status_t 
exportRegistration_start(export_registration_t *reg) {
 
     if (prevTrkId >= 0) {
         celix_logHelper_error(reg->helper, "Error starting export 
registration. The export registration already had an active service tracker");
-        celix_bundleContext_stopTracker(reg->context, prevTrkId);
+        celix_bundleContext_stopTrackerAsync(reg->context, prevTrkId, NULL, 
NULL);
     }
 
     return status;
 }
 
-
-celix_status_t exportRegistration_stop(export_registration_t *reg) {
-    celix_status_t status = CELIX_SUCCESS;
-    if (status == CELIX_SUCCESS) {
-        status = bundleContext_ungetServiceReference(reg->context, 
reg->exportReference.reference);
-
-        celixThreadMutex_lock(&reg->mutex);
-        long trkId = reg->trackerId;
-        reg->trackerId = -1L;
-        celixThreadMutex_unlock(&reg->mutex);
-        celix_bundleContext_stopTracker(reg->context, trkId);
-
-    }
-    return status;
-}
-
 void exportRegistration_setActive(export_registration_t *reg, bool active) {
     celixThreadMutex_lock(&reg->mutex);
     reg->active = active;
diff --git 
a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
 
b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
index e290442..b07b869 100644
--- 
a/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
+++ 
b/bundles/remote_services/remote_service_admin_dfi/src/export_registration_dfi.h
@@ -29,7 +29,6 @@ celix_status_t exportRegistration_create(celix_log_helper_t 
*helper, service_ref
 void exportRegistration_destroy(export_registration_t *registration);
 
 celix_status_t exportRegistration_start(export_registration_t *registration);
-celix_status_t exportRegistration_stop(export_registration_t *registration);
 void exportRegistration_setActive(export_registration_t *registration, bool 
active);
 
 celix_status_t exportRegistration_call(export_registration_t *export, char 
*data, int datalength, celix_properties_t *metadata, char **response, int 
*responseLength);
diff --git 
a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
 
b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
index 2c4e8dc..351415a 100644
--- 
a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
+++ 
b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.c
@@ -126,22 +126,32 @@ static void 
importRegistration_clearProxies(import_registration_t *import) {
     }
 }
 
-void importRegistration_destroy(import_registration_t *import) {
-    if (import != NULL) {
-        if (import->proxies != NULL) {
-            hashMap_destroy(import->proxies, false, false);
-            import->proxies = NULL;
-        }
+static void importRegistration_destroyCallback(void* data) {
+    import_registration_t* import = data;
+    importRegistration_clearProxies(import);
+    if (import->proxies != NULL) {
+        hashMap_destroy(import->proxies, false, false);
+        import->proxies = NULL;
+    }
 
-        remoteInterceptorsHandler_destroy(import->interceptorsHandler);
+    remoteInterceptorsHandler_destroy(import->interceptorsHandler);
 
-        pthread_mutex_destroy(&import->mutex);
-        pthread_mutex_destroy(&import->proxiesMutex);
+    pthread_mutex_destroy(&import->mutex);
+    pthread_mutex_destroy(&import->proxiesMutex);
 
-        if(import->version!=NULL){
-               version_destroy(import->version);
+    if (import->version != NULL) {
+        version_destroy(import->version);
+    }
+    free(import);
+}
+
+void importRegistration_destroy(import_registration_t *import) {
+    if (import != NULL) {
+        if (import->factorySvcId >= 0) {
+            celix_bundleContext_unregisterServiceAsync(import->context, 
import->factorySvcId, import, importRegistration_destroyCallback);
+        } else {
+            importRegistration_destroyCallback(import);
         }
-        free(import);
     }
 }
 
@@ -151,15 +161,6 @@ celix_status_t 
importRegistration_start(import_registration_t *import) {
     return import->factorySvcId >= 0 ? CELIX_SUCCESS : CELIX_ILLEGAL_STATE;
 }
 
-celix_status_t importRegistration_stop(import_registration_t *import) {
-    if (import != NULL) {
-        celix_bundleContext_unregisterService(import->context, 
import->factorySvcId);
-        import->factorySvcId = -1;
-        importRegistration_clearProxies(import);
-    }
-    return CELIX_SUCCESS;
-}
-
 static void* importRegistration_getService(void *handle, const celix_bundle_t 
*requestingBundle, const celix_properties_t *svcProperties) {
     celix_status_t  status = CELIX_SUCCESS;
     void* svc = NULL;
@@ -385,13 +386,6 @@ static void importRegistration_destroyProxy(struct 
service_proxy *proxy) {
     }
 }
 
-
-celix_status_t importRegistration_close(import_registration_t *registration) {
-    celix_status_t status = CELIX_SUCCESS;
-    importRegistration_stop(registration);
-    return status;
-}
-
 celix_status_t importRegistration_getException(import_registration_t 
*registration) {
     celix_status_t status = CELIX_SUCCESS;
     //TODO
diff --git 
a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
 
b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
index 7f4c3a1..9c4951e 100644
--- 
a/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
+++ 
b/bundles/remote_services/remote_service_admin_dfi/src/import_registration_dfi.h
@@ -29,13 +29,11 @@ typedef void (*send_func_type)(void *handle, 
endpoint_description_t *endpointDes
 
 celix_status_t importRegistration_create(celix_bundle_context_t *context, 
endpoint_description_t *description, const char *classObject, const char* 
serviceVersion, FILE *logFile,
                                          import_registration_t **import);
-celix_status_t importRegistration_close(import_registration_t *import);
 void importRegistration_destroy(import_registration_t *import);
 
 celix_status_t importRegistration_setSendFn(import_registration_t *reg,
                                             send_func_type,
                                             void *handle);
 celix_status_t importRegistration_start(import_registration_t *import);
-celix_status_t importRegistration_stop(import_registration_t *import);
 
 #endif //CELIX_IMPORT_REGISTRATION_DFI_H
diff --git 
a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
 
b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
index 9de4518..432d79d 100644
--- 
a/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
+++ 
b/bundles/remote_services/remote_service_admin_dfi/src/remote_service_admin_dfi.c
@@ -320,7 +320,6 @@ void* remoteServiceAdmin_stopExportsThread(void *data) {
         }
         for (int i = 0; i < celix_arrayList_size(admin->stopExports); ++i) {
             export_registration_t *export = 
celix_arrayList_get(admin->stopExports, i);
-            exportRegistration_stop(export);
             exportRegistration_destroy(export);
         }
         celix_arrayList_clear(admin->stopExports);
@@ -365,7 +364,6 @@ static void 
remoteServiceAdmin_stopExport(remote_service_admin_t *admin, export_
             celixThreadMutex_unlock(&admin->stopExportsMutex);
         } else {
             exportRegistration_waitTillNotUsed(export);
-            exportRegistration_stop(export);
             exportRegistration_destroy(export);
         }
     }
@@ -397,7 +395,6 @@ celix_status_t 
remoteServiceAdmin_stop(remote_service_admin_t *admin) {
     for (i = 0; i < size ; i += 1) {
         import_registration_t *import = arrayList_get(admin->importedServices, 
i);
         if (import != NULL) {
-            importRegistration_stop(import);
             importRegistration_destroy(import);
         }
     }
@@ -617,7 +614,6 @@ celix_status_t 
remoteServiceAdmin_exportService(remote_service_admin_t *admin, c
             export_registration_t *registration = NULL;
 
             remoteServiceAdmin_createEndpointDescription(admin, reference, 
properties, (char *) interface, &endpoint);
-            //TODO precheck if descriptor exists
             status = exportRegistration_create(admin->loghelper, reference, 
endpoint, admin->context, admin->logFile,
                                                &registration);
             if (status == CELIX_SUCCESS) {
@@ -876,7 +872,6 @@ celix_status_t 
remoteServiceAdmin_removeImportedService(remote_service_admin_t *
         current = arrayList_get(admin->importedServices, i);
         if (current == registration) {
             arrayList_remove(admin->importedServices, i);
-            importRegistration_close(current);
             importRegistration_destroy(current);
             break;
         }

Reply via email to