celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject svn commit: r1621877 - in /celix/trunk/remote_services/remote_service_admin_shm/private: include/remote_service_admin_shm_impl.h src/remote_service_admin_impl.c
Date Mon, 01 Sep 2014 20:32:23 GMT
Author: bpetri
Date: Mon Sep  1 20:32:22 2014
New Revision: 1621877

URL: http://svn.apache.org/r1621877
Log:

CELIX-147

check if sync. semaphores are set before sending and reset them if needed


Modified:
    celix/trunk/remote_services/remote_service_admin_shm/private/include/remote_service_admin_shm_impl.h
    celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c

Modified: celix/trunk/remote_services/remote_service_admin_shm/private/include/remote_service_admin_shm_impl.h
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_shm/private/include/remote_service_admin_shm_impl.h?rev=1621877&r1=1621876&r2=1621877&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_shm/private/include/remote_service_admin_shm_impl.h
(original)
+++ celix/trunk/remote_services/remote_service_admin_shm/private/include/remote_service_admin_shm_impl.h
Mon Sep  1 20:32:22 2014
@@ -46,6 +46,12 @@
 	#define P_tmpdir "/tmp"
 #endif
 
+union semun {
+	int              val;    /* Value for SETVAL */
+	struct semid_ds *buf;    /* Buffer for IPC_STAT, IPC_SET */
+	unsigned short  *array;  /* Array for GETALL, SETALL */
+	struct seminfo  *__buf;  /* Buffer for IPC_INFO */
+};
 
 struct recv_shm_thread
 {

Modified: celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
URL: http://svn.apache.org/viewvc/celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c?rev=1621877&r1=1621876&r2=1621877&view=diff
==============================================================================
--- celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
(original)
+++ celix/trunk/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
Mon Sep  1 20:32:22 2014
@@ -29,6 +29,7 @@
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <sys/sem.h>
+#include <sys/ipc.h>
 #include <sys/shm.h>
 #include <unistd.h>
 #include <apr_uuid.h>
@@ -49,13 +50,13 @@
 #include "service_registration.h"
 #include "netstring.h"
 
-celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_pt admin, export_registration_pt
registration, service_reference_pt reference, char *interface);
-celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin,
properties_pt serviceProperties, properties_pt endpointProperties, char *interface, endpoint_description_pt
*description);
 
-celix_status_t remoteServiceAdmin_lock(int semId, int semNr);
-celix_status_t remoteServiceAdmin_unlock(int semId, int semNr);
-celix_status_t remoteServiceAdmin_wait(int semId, int semNr);
+static celix_status_t remoteServiceAdmin_lock(int semId, int semNr);
+static celix_status_t remoteServiceAdmin_unlock(int semId, int semNr);
+static int remoteServiceAdmin_getCount(int semId, int semNr);
 
+celix_status_t remoteServiceAdmin_installEndpoint(remote_service_admin_pt admin, export_registration_pt
registration, service_reference_pt reference, char *interface);
+celix_status_t remoteServiceAdmin_createEndpointDescription(remote_service_admin_pt admin,
properties_pt serviceProperties, properties_pt endpointProperties, char *interface, endpoint_description_pt
*description);
 
 celix_status_t remoteServiceAdmin_createOrAttachShm(hash_map_pt ipcSegment, remote_service_admin_pt
admin, endpoint_description_pt endpointDescription, bool createIfNotFound);
 celix_status_t remoteServiceAdmin_getIpcSegment(remote_service_admin_pt admin, endpoint_description_pt
endpointDescription, ipc_segment_pt* ipc);
@@ -66,6 +67,8 @@ celix_status_t remoteServiceAdmin_getSha
 celix_status_t remoteServiceAdmin_removeSharedIdentityFile(char *fwUuid, char* servicename);
 celix_status_t remoteServiceAdmin_removeSharedIdentityFiles(char* fwUuid);
 
+static bool lockHolder[3];
+
 celix_status_t remoteServiceAdmin_create(apr_pool_t *pool, bundle_context_pt context, remote_service_admin_pt
*admin)
 {
     celix_status_t status = CELIX_SUCCESS;
@@ -195,40 +198,31 @@ celix_status_t remoteServiceAdmin_stop(r
 }
 
 
-celix_status_t remoteServiceAdmin_lock(int semId, int semNr)
+static int remoteServiceAdmin_getCount(int semId, int semNr)
 {
-    celix_status_t status = CELIX_SUCCESS;
-    int semOpStatus = 0;
-    struct sembuf semOperation;
+	int token = -1;
+	unsigned short semVals[3];
+	union semun semArg;
 
-    semOperation.sem_num = semNr;
-    semOperation.sem_op = -1;
-    semOperation.sem_flg = 0;
-
-    do
-    {
-        status = CELIX_SUCCESS;
-
-        if ((semOpStatus = semop(semId, &semOperation, 1)) != 0)
-        {
-            status = CELIX_BUNDLE_EXCEPTION;
-        }
-    }
-    while (semOpStatus == -1 && errno == EINTR);
+	semArg.array = semVals;
 
+	if(semctl(semId,0,GETALL,semArg) == 0)
+	{
+		token = semArg.array[semNr];
+	}
 
-    return status;
+	return token;
 }
 
 
-celix_status_t remoteServiceAdmin_unlock(int semId, int semNr)
+static celix_status_t remoteServiceAdmin_lock(int semId, int semNr)
 {
     celix_status_t status = CELIX_SUCCESS;
     int semOpStatus = 0;
     struct sembuf semOperation;
 
     semOperation.sem_num = semNr;
-    semOperation.sem_op = 1;
+    semOperation.sem_op = -1;
     semOperation.sem_flg = 0;
 
     do
@@ -242,17 +236,19 @@ celix_status_t remoteServiceAdmin_unlock
     }
     while (semOpStatus == -1 && errno == EINTR);
 
+
     return status;
 }
 
-celix_status_t remoteServiceAdmin_wait(int semId, int semNr)
+
+static celix_status_t remoteServiceAdmin_unlock(int semId, int semNr)
 {
     celix_status_t status = CELIX_SUCCESS;
     int semOpStatus = 0;
     struct sembuf semOperation;
 
     semOperation.sem_num = semNr;
-    semOperation.sem_op = 0;
+    semOperation.sem_op = 1;
     semOperation.sem_flg = 0;
 
     do
@@ -290,12 +286,26 @@ celix_status_t remoteServiceAdmin_send(r
             char *fncCallReply = NULL;
             char *fncCallReplyStatus = CELIX_SUCCESS;
 
+            /* lock critical area */
             remoteServiceAdmin_lock(semid, 0);
 
-            strcpy(ipc->shmBaseAdress, encFncCallProps);
+			strcpy(ipc->shmBaseAdress, encFncCallProps);
 
-            remoteServiceAdmin_unlock(semid, 1);
-            remoteServiceAdmin_lock(semid, 2);
+			/* Check the status of the send-receive semaphore and reset them if not correct */
+			if (remoteServiceAdmin_getCount(ipc->semId,1) > 0)
+			{
+				semctl(semid, 1, SETVAL, (int) 0);
+			}
+			if (remoteServiceAdmin_getCount(ipc->semId,2) > 0)
+			{
+				semctl(semid, 2, SETVAL, (int) 0);
+			}
+
+			/* Inform receiver we are invoking the remote service */
+			remoteServiceAdmin_unlock(semid, 1);
+
+			/* Wait until the receiver finished his operations */
+			remoteServiceAdmin_lock(semid, 2);
 
             if ((status = netstring_decodeToHashMap(admin->pool, ipc->shmBaseAdress,
fncCallProps)) == CELIX_SUCCESS)
             {
@@ -312,6 +322,8 @@ celix_status_t remoteServiceAdmin_send(r
             {
             	*replyStatus = apr_atoi64(fncCallReplyStatus);
             }
+
+            /* release critical area */
             remoteServiceAdmin_unlock(semid, 0);
         }
         hashMap_destroy(fncCallProps, false, false);



Mime
View raw message