From 7811f7c3df872170e09a6bbdc31d8cd335c0ef7b Mon Sep 17 00:00:00 2001 From: glenux Date: Tue, 24 Feb 2004 09:22:26 +0000 Subject: [PATCH] *** empty log message *** --- src/ids.c | 21 ++++++++++++++++++--- src/proto.h | 3 ++- src/queueInit.c | 47 +++++++++++++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/ids.c b/src/ids.c index 790600d..4adc693 100644 --- a/src/ids.c +++ b/src/ids.c @@ -87,7 +87,7 @@ int msgBufferInfoTabIdIntern( return 0; } -int msgQueueSemIdIntern( +int msgQueueProtSemIdIntern( msgQueueSemId dest, msgSpaceId externId, int queueIdx){ @@ -95,9 +95,24 @@ int msgQueueSemIdIntern( return -1; } #ifdef _NZG_REALFILEID - sprintf(dest,"/tmp/nzgQueue-%s-%d",(char *)externId,queueIdx); + sprintf(dest,"/tmp/nzgQueueProtSem-%s-%d",(char *)externId,queueIdx); #else - sprintf(dest,"/nzgQueue-%s-%d",(char *)externId,queueIdx); + sprintf(dest,"/nzgQueueProtSem-%s-%d",(char *)externId,queueIdx); +#endif + return 0; +} + +int msgQueueReadSemIdIntern( + msgQueueSemId dest, + msgSpaceId externId, + int queueIdx){ + if (strlen(externId)>MSGSPACE_ID_LEN){ + return -1; + } +#ifdef _NZG_REALFILEID + sprintf(dest,"/tmp/nzgQueueReadSem-%s-%d",(char *)externId,queueIdx); +#else + sprintf(dest,"/nzgQueueReadSem-%s-%d",(char *)externId,queueIdx); #endif return 0; } diff --git a/src/proto.h b/src/proto.h index ecbd732..ccd471d 100644 --- a/src/proto.h +++ b/src/proto.h @@ -26,7 +26,8 @@ int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int p int msgPoolDataIdIntern(msgPoolDataTabId dest, const msgSpaceId src); int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num); int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num); -int msgQueueSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx); +int msgQueueProtSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx); +int msgQueueReadSemIdIntern(msgQueueSemId dest, msgSpaceId externId, int queueIdx); int msgQueueIdIntern(msgQueueId dest, msgSpaceId externId, int queueIdx); int msgQueueElemIdIntern(msgQueueElemId dest, msgQueueId src, int counter); int spaceListElemIdIntern(msgSpaceListElemId elemListId, msgSpaceId externId); diff --git a/src/queueInit.c b/src/queueInit.c index a156388..13d7fb7 100644 --- a/src/queueInit.c +++ b/src/queueInit.c @@ -4,11 +4,38 @@ msgQueue * queueInit(msgSpaceId externId, int queueIdx) { int queueFd; msgQueue * queue; - sem_t * semaphore; + sem_t * semProtectFd; + msgQueueSemId queueSemProtectId; + sem_t * semReadableFd; + msgQueueSemId queueSemReadableId; msgQueueId queueId; queue = NULL; + + msgQueueProtSemIdIntern(queueSemProtectId,externId,queueIdx); + msgQueueReadSemIdIntern(queueSemReadableId,externId,queueIdx); + + // creation du semaphore de lecture + semReadableFd = sem_open(queueSemReadableId, + O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 0); + if(semReadableFd == SEM_FAILED) { + NZG_ERROR("sem_open", queueSemReadableId); + goto ERROR; + } + // creation du semaphore de protection + semProtectFd = sem_open(queueSemProtectId, + O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 1); + if(semProtectFd == SEM_FAILED) { + NZG_ERROR("sem_open", queueSemProtectId); + goto ERROR; + } + + if(sem_wait(semProtectFd)==-1){ + NZG_ERROR("sem_wait",queueSemProtectId); + goto ERROR; + } + if(msgQueueIdIntern(queueId, externId, queueIdx) < 0) { return NULL; } @@ -32,25 +59,13 @@ msgQueue * queueInit(msgSpaceId externId, int queueIdx) { strcpy(queue->tailId,queue->id); - - // creation du semaphore - semaphore = sem_open(queueId, O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 1); - if(semaphore == SEM_FAILED) { - NZG_ERROR("sem_open", queueId); - goto ERROR; - } - -if(sem_wait(semaphore)==-1){ - NZG_ERROR("sem_wait",queueId); - goto ERROR; - } /* on ferme tout ce qu'il faut */ - sem_close(semaphore); + sem_close(semProtectFd); close(queueFd); - + return queue; ERROR: return NULL; - + }