diff --git a/src/poolDataTabLock.c b/src/poolDataTabLock.c index 08d4b08..0baaf98 100644 --- a/src/poolDataTabLock.c +++ b/src/poolDataTabLock.c @@ -19,6 +19,9 @@ printf("Locking %s\n",space->poolDataTabSemId); NZG_ERROR("sem_wait",space->poolDataTabSemId); goto ERROR; } + int semval=0; + sem_getvalue(poolDataTabSemFd,&semval); + printf("(AfternValue:%d)\n",semval); sem_close(poolDataTabSemFd); diff --git a/src/poolDataTabUnlock.c b/src/poolDataTabUnlock.c index 4a8a674..b6eb8c9 100644 --- a/src/poolDataTabUnlock.c +++ b/src/poolDataTabUnlock.c @@ -4,15 +4,12 @@ int msgPoolDataTabUnlock(msgSpace * space){ sem_t * poolDataTabSemFd; -printf("Locking %s\n",space->poolDataTabSemId); +printf("Unlocking %s\n",space->poolDataTabSemId); poolDataTabSemFd=sem_open( space->poolDataTabSemId ,O_CREAT, SEM_DEFAULT_MODE, 1); - int semval=0; - sem_getvalue(poolDataTabSemFd,&semval); - printf("(Value:%d)",semval); if(poolDataTabSemFd==SEM_FAILED){ NZG_ERROR("sem_open",space->poolDataTabSemId); goto ERROR; @@ -22,6 +19,9 @@ printf("Locking %s\n",space->poolDataTabSemId); NZG_ERROR("sem_post",space->poolDataTabSemId); goto ERROR; } + int semval=0; + sem_getvalue(poolDataTabSemFd,&semval); + printf("(AfternValue:%d)\n",semval); sem_close(poolDataTabSemFd); diff --git a/src/put.c b/src/put.c index 50cab6e..cb2e236 100644 --- a/src/put.c +++ b/src/put.c @@ -6,6 +6,9 @@ int msgPut(msgSpace * space,int queueIndex, void * addr){ int poolIndex; int bufferIndex; int err; + msgQueueElemId newElemId; + msgQueueElem * queueElem; + msgPoolDataTabLock(space); poolDataTabAddr=msgPoolDataTabOpen(space); if (poolDataTabAddr == NULL){ @@ -28,10 +31,8 @@ int msgPut(msgSpace * space,int queueIndex, void * addr){ msgQueueProtLock(space->externId,queueIndex); queue = msgQueueOpen(queueId); - // TODO:creer un element vide - msgQueueElemId newElemId; - msgQueueElem * queueElem; - + // creer un element vide + msgQueueElemCreate(newElemId,queueId,queue->elemCounter); // ouvrir l'element queueElem=msgQueueElemOpen(newElemId); diff --git a/src/queueInit.c b/src/queueInit.c index ef524df..b07bb01 100644 --- a/src/queueInit.c +++ b/src/queueInit.c @@ -12,7 +12,6 @@ msgQueue * msgQueueInit(msgSpaceId externId, int queueIdx) { queue = NULL; - printf("ploped init queue ?\n"); msgQueueProtSemIdIntern(queueSemProtectId,externId,queueIdx); msgQueueReadSemIdIntern(queueSemReadableId,externId,queueIdx); @@ -27,16 +26,16 @@ msgQueue * msgQueueInit(msgSpaceId externId, int queueIdx) { // creation du semaphore de protection semProtectFd = sem_open(queueSemProtectId, - O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 1); + O_CREAT|O_EXCL, SEM_DEFAULT_MODE, 0); if(semProtectFd == SEM_FAILED) { NZG_ERROR("sem_open", queueSemProtectId); goto ERROR; } - if(sem_wait(semProtectFd)==-1){ +/* if(sem_wait(semProtectFd)==-1){ NZG_ERROR("sem_wait",queueSemProtectId); goto ERROR; - } + } */ if(msgQueueIdIntern(queueId, externId, queueIdx) < 0) { return NULL; @@ -44,27 +43,26 @@ msgQueue * msgQueueInit(msgSpaceId externId, int queueIdx) { queueFd = shm_open(queueId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, MSGSPACE_DEFAULT_MODE); if(queueFd == -1) { - fprintf(stderr, "queueInit : %s initialisation failed: %s\n", queueId, strerror(errno)); - return NULL; + NZG_ERROR("shm_open : queueInit",queueId); + return NULL; } - if(ftruncate(queueFd, sizeof(* queue)) == -1) { - fprintf( stderr, "Queue resizing failed: %s\n", - strerror( errno ) ); - return NULL; - } - + if(ftruncate(queueFd, sizeof(msgQueue)) == -1) { + fprintf( stderr, "Queue resizing failed: %s\n", + strerror( errno ) ); + return NULL; + } + queue=msgQueueOpen(queueId); /* on remplit la structure msgQueue */ queue->elemCounter = 0; + strcpy(queue->id,queueId); strcpy(queue->headId,queue->id); strcpy(queue->tailId,queue->id); - - /* on ferme tout ce qu'il faut */ - sem_close(semProtectFd); close(queueFd); + msgQueueProtUnlock(externId,queueIdx); return queue; ERROR: diff --git a/src/queueProtLock.c b/src/queueProtLock.c index 6494c93..43125b9 100644 --- a/src/queueProtLock.c +++ b/src/queueProtLock.c @@ -6,7 +6,8 @@ int msgQueueProtLock(msgSpaceId externId,int queueIdx){ msgQueueSemId queueSemId; msgQueueProtSemIdIntern(queueSemId,externId,queueIdx); - queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + printf("Locking %s\n",queueSemId); + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -16,6 +17,12 @@ int msgQueueProtLock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_wait",queueSemId); goto ERROR; } + int semval=0; + sem_getvalue(queueSemFd,&semval); + printf("(AfterValue:%d)\n",semval); + + sem_close(queueSemFd); + sem_close(queueSemFd); diff --git a/src/queueProtUnlock.c b/src/queueProtUnlock.c index 5e521a3..7bd5671 100644 --- a/src/queueProtUnlock.c +++ b/src/queueProtUnlock.c @@ -6,7 +6,9 @@ int msgQueueProtUnlock(msgSpaceId externId,int queueIdx){ msgQueueSemId queueSemId; msgQueueProtSemIdIntern(queueSemId,externId,queueIdx); - queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + printf("Unlocking %s\n",queueSemId); + + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -16,6 +18,9 @@ int msgQueueProtUnlock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_post",queueSemId); goto ERROR; } + int semval=0; + sem_getvalue(queueSemFd,&semval); + printf("(AfterValue:%d)\n",semval); sem_close(queueSemFd); diff --git a/src/queueReadLock.c b/src/queueReadLock.c index 99e2ab3..2d9c79e 100644 --- a/src/queueReadLock.c +++ b/src/queueReadLock.c @@ -6,7 +6,8 @@ int msgQueueReadLock(msgSpaceId externId,int queueIdx){ msgQueueSemId queueSemId; msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); - queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + printf("Locking %s\n",queueSemId); + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -16,6 +17,12 @@ int msgQueueReadLock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_wait",queueSemId); goto ERROR; } + int semval=0; + sem_getvalue(queueSemFd,&semval); + printf("(AfterValue:%d)\n",semval); + + sem_close(queueSemFd); + sem_close(queueSemFd); diff --git a/src/queueReadTryLock.c b/src/queueReadTryLock.c index b3292ca..4c3e597 100644 --- a/src/queueReadTryLock.c +++ b/src/queueReadTryLock.c @@ -6,7 +6,7 @@ int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){ msgQueueSemId queueSemId; msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); - queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -16,6 +16,13 @@ int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_wait",queueSemId); goto ERROR; } + printf("Locking %s\n",queueSemId); + int semval=0; + sem_getvalue(queueSemFd,&semval); + printf("(AfterValue:%d)\n",semval); + + sem_close(queueSemFd); + sem_close(queueSemFd); diff --git a/src/queueReadUnlock.c b/src/queueReadUnlock.c index d3e7a10..717cefa 100644 --- a/src/queueReadUnlock.c +++ b/src/queueReadUnlock.c @@ -6,7 +6,8 @@ int msgQueueReadUnlock(msgSpaceId externId,int queueIdx){ msgQueueSemId queueSemId; msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); - queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + printf("Unlocking %s\n",queueSemId); + queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); goto ERROR; @@ -16,6 +17,10 @@ int msgQueueReadUnlock(msgSpaceId externId,int queueIdx){ NZG_ERROR("sem_post",queueSemId); goto ERROR; } + int semval=0; + sem_getvalue(queueSemFd,&semval); + printf("(AfterValue:%d)\n",semval); + sem_close(queueSemFd); diff --git a/src/spaceCreate.c b/src/spaceCreate.c index 7dacd25..e1f4fbc 100644 --- a/src/spaceCreate.c +++ b/src/spaceCreate.c @@ -95,8 +95,6 @@ msgSpace * msgSpaceCreate( } sem_close(mSDataTabSemFd); -// msgPoolDataTabLock(space); - /* attacher le tableau des msgPoolData */ poolDataTabAddr=msgPoolDataTabCreate(space); if (poolDataTabAddr == NULL){ diff --git a/test/put_get.c b/test/put_get.c index 8bfe94c..ce4b3b7 100644 --- a/test/put_get.c +++ b/test/put_get.c @@ -26,6 +26,7 @@ int main(void) { } printf("CREATION ------------------ ok\n"); + sleep(1); pid_t pid=fork(); if (pid ==0){