You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@celix.apache.org by pn...@apache.org on 2020/01/26 18:54:56 UTC
[celix] branch feature/gh-142-rsa-issues updated: gh-142: Replace
mutex with rw lock in rsa to support handling multiple calls and adds
missing test for libdfi
This is an automated email from the ASF dual-hosted git repository.
pnoltes pushed a commit to branch feature/gh-142-rsa-issues
in repository https://gitbox.apache.org/repos/asf/celix.git
The following commit(s) were added to refs/heads/feature/gh-142-rsa-issues by this push:
new 8c68686 gh-142: Replace mutex with rw lock in rsa to support handling multiple calls and adds missing test for libdfi
8c68686 is described below
commit 8c686863118522cf5c9b3370842379c3b372b701
Author: Pepijn Noltes <pe...@gmail.com>
AuthorDate: Sun Jan 26 19:54:14 2020 +0100
gh-142: Replace mutex with rw lock in rsa to support handling multiple calls and adds missing test for libdfi
---
.../src/endpoint_discovery_server.c | 2 +-
.../src/remote_service_admin_dfi.c | 22 +++++++--------
libs/dfi/include/dyn_function.h | 5 ++++
libs/dfi/test/dyn_function_tests.cpp | 32 ++++++++++++++++++++++
4 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/bundles/remote_services/discovery_common/src/endpoint_discovery_server.c b/bundles/remote_services/discovery_common/src/endpoint_discovery_server.c
index 5ad8e87..ba31c9d 100644
--- a/bundles/remote_services/discovery_common/src/endpoint_discovery_server.c
+++ b/bundles/remote_services/discovery_common/src/endpoint_discovery_server.c
@@ -40,7 +40,7 @@
// defines how often the webserver is restarted (with an increased port number)
#define MAX_NUMBER_OF_RESTARTS 15
-#define DEFAULT_SERVER_THREADS "1"
+#define DEFAULT_SERVER_THREADS "5"
#define CIVETWEB_REQUEST_NOT_HANDLED 0
#define CIVETWEB_REQUEST_HANDLED 1
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 2d57df7..eb45cf8 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
@@ -60,7 +60,7 @@ struct remote_service_admin {
celix_bundle_context_t *context;
log_helper_t *loghelper;
- celix_thread_mutex_t exportedServicesLock;
+ celix_thread_rwlock_t exportedServicesLock;
hash_map_pt exportedServices;
celix_thread_mutex_t importedServicesLock;
@@ -118,8 +118,8 @@ celix_status_t remoteServiceAdmin_create(celix_bundle_context_t *context, remote
(*admin)->exportedServices = hashMap_create(NULL, NULL, NULL, NULL);
arrayList_create(&(*admin)->importedServices);
- celixThreadMutex_create(&(*admin)->exportedServicesLock, NULL);
- celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
+ celixThreadRwlock_create(&(*admin)->exportedServicesLock, NULL);
+ celixThreadMutex_create(&(*admin)->importedServicesLock, NULL);
if (logHelper_create(context, &(*admin)->loghelper) == CELIX_SUCCESS) {
logHelper_start((*admin)->loghelper);
@@ -217,7 +217,7 @@ celix_status_t remoteServiceAdmin_destroy(remote_service_admin_t **admin)
celix_status_t remoteServiceAdmin_stop(remote_service_admin_t *admin) {
celix_status_t status = CELIX_SUCCESS;
- celixThreadMutex_lock(&admin->exportedServicesLock);
+ celixThreadRwlock_writeLock(&admin->exportedServicesLock);
hash_map_iterator_pt iter = hashMapIterator_create(admin->exportedServices);
while (hashMapIterator_hasNext(iter)) {
@@ -233,7 +233,7 @@ celix_status_t remoteServiceAdmin_stop(remote_service_admin_t *admin) {
arrayList_destroy(exports);
}
hashMapIterator_destroy(iter);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
+ celixThreadRwlock_unlock(&admin->exportedServicesLock);
celixThreadMutex_lock(&admin->importedServicesLock);
int i;
@@ -291,7 +291,7 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) {
service[pos] = '\0';
unsigned long serviceId = strtoul(service,NULL,10);
- celixThreadMutex_lock(&rsa->exportedServicesLock);
+ celixThreadRwlock_readLock(&rsa->exportedServicesLock);
//find endpoint
export_registration_t *export = NULL;
@@ -345,7 +345,7 @@ static int remoteServiceAdmin_callback(struct mg_connection *conn) {
RSA_LOG_WARNING(rsa, "No export registration found for service id %lu", serviceId);
}
- celixThreadMutex_unlock(&rsa->exportedServicesLock);
+ celixThreadRwlock_unlock(&rsa->exportedServicesLock);
}
}
@@ -442,9 +442,9 @@ celix_status_t remoteServiceAdmin_exportService(remote_service_admin_t *admin, c
if (status == CELIX_SUCCESS) {
- celixThreadMutex_lock(&admin->exportedServicesLock);
+ celixThreadRwlock_writeLock(&admin->exportedServicesLock);
hashMap_put(admin->exportedServices, reference, *registrations);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
+ celixThreadRwlock_unlock(&admin->exportedServicesLock);
} else {
arrayList_destroy(*registrations);
*registrations = NULL;
@@ -464,7 +464,7 @@ celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_t *
if (status == CELIX_SUCCESS && ref != NULL) {
service_reference_pt servRef;
- celixThreadMutex_lock(&admin->exportedServicesLock);
+ celixThreadRwlock_writeLock(&admin->exportedServicesLock);
exportReference_getExportedService(ref, &servRef);
array_list_pt exports = (array_list_pt)hashMap_remove(admin->exportedServices, servRef);
@@ -475,7 +475,7 @@ celix_status_t remoteServiceAdmin_removeExportedService(remote_service_admin_t *
exportRegistration_close(registration);
exportRegistration_destroy(registration);
- celixThreadMutex_unlock(&admin->exportedServicesLock);
+ celixThreadRwlock_unlock(&admin->exportedServicesLock);
free(ref);
diff --git a/libs/dfi/include/dyn_function.h b/libs/dfi/include/dyn_function.h
index 16c0fd1..4b92456 100644
--- a/libs/dfi/include/dyn_function.h
+++ b/libs/dfi/include/dyn_function.h
@@ -31,6 +31,11 @@
* am=handle #void pointer for the handle
* am=pre #output pointer with memory pre-allocated
* am=out #output pointer
+ *
+ * text argument (t) can also be annotated to be considered const string.
+ * Normally a text argument will be handled as char*, meaning that the callee is expected to take of ownership.
+ * If a const=true annotation is used the text argument will be handled as a const char*, meaning that the caller
+ * keeps ownership of the string.
*/
typedef struct _dyn_function_type dyn_function_type;
diff --git a/libs/dfi/test/dyn_function_tests.cpp b/libs/dfi/test/dyn_function_tests.cpp
index b5efd15..3073a98 100644
--- a/libs/dfi/test/dyn_function_tests.cpp
+++ b/libs/dfi/test/dyn_function_tests.cpp
@@ -223,6 +223,34 @@ extern "C" {
dynFunction_destroy(dynFunc);
}
+ #define EXAMPLE5_DESCRIPTOR "example(#const=true;tt)V"
+
+ static void example5Func(const char *s1, char *s2) {
+ STRCMP_EQUAL("s1", s1);
+ STRCMP_EQUAL("s2", s2);
+ }
+
+ static void test_example5(void) {
+ dyn_function_type *dynFunc = NULL;
+ void (*fp)(void) = (void(*)(void)) example5Func;
+ int rc;
+
+ rc = dynFunction_parseWithStr(EXAMPLE5_DESCRIPTOR, NULL, &dynFunc);
+ CHECK_EQUAL(0, rc);
+
+ const char *a1 = "s1";
+ char *a2 = strdup("s2");
+ void *args[2];
+ args[0] = &a1;
+ args[1] = &a2;
+
+ rc = dynFunction_call(dynFunc, fp, NULL, args);
+ CHECK_EQUAL(0, rc);
+
+ dynFunction_destroy(dynFunc);
+ }
+
+
#define INVALID_FUNC_DESCRIPTOR "example$[D)V"//$ is an invalid symbol, missing (
static void test_invalidDynFunc(void) {
@@ -269,6 +297,10 @@ TEST(DynFunctionTests, DynFuncTest4) {
test_example4();
}
+TEST(DynFunctionTests, DynFuncTest5) {
+ test_example5();
+}
+
TEST(DynFunctionTests, InvalidDynFuncTest) {
test_invalidDynFunc();
test_invalidDynFuncType();