From a96c647b0b5a0e1b6a679082f4c7ac6bb25bdb6d Mon Sep 17 00:00:00 2001 From: glenux Date: Wed, 25 Feb 2004 11:22:38 +0000 Subject: [PATCH] *** empty log message *** --- src/free.c | 21 +++++++-------------- test/put_get.c | 32 +++++++++++++------------------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/src/free.c b/src/free.c index 58a4dba..92d2e91 100644 --- a/src/free.c +++ b/src/free.c @@ -6,25 +6,20 @@ int msgFree(msgSpace * space, void * addr){ int poolIndex; int bufferIndex; msgPoolData * poolDataTabAddr; -sem_t * poolDataTabSemFd; - msgPoolDataTabSemId ressourceSemId; sem_t * ressourceSemFd; - /* on acquiert le droit de modifier les infos sur la ressource */ + msgPoolDataTabSemId ressourceSemId; + /* on acquiert le droit de modifier les infos sur la ressource */ /* on protege le tableau des associations */ - poolDataTabSemFd=sem_open(space->poolDataTabSemId, - O_CREAT,SEM_DEFAULT_MODE,1); - if (poolDataTabSemFd == SEM_FAILED){ - NZG_ERROR("sem_open : ouverture de la ressource", - space->poolDataTabSemId); - return -1; - } - sem_wait(poolDataTabSemFd); + if (msgPoolDataTabLock(space) <0){ + NZG_ERROR("msgPoolDataTabLock",space->poolDataTabSemId); + goto ERROR; + }; /* verifier le premier arg du shm_open */ poolDataTabAddr = msgPoolDataTabOpen(space); - // TODO: verouiller semaphore DataInfo + // TODO: verouiller semaphore DataInfo ?? int err; poolIndex=-1; bufferIndex=-1; @@ -51,8 +46,6 @@ sem_t * poolDataTabSemFd; // deverouiller semaphore DataInfo msgPoolDataTabUnlock(space); -// sem_post(poolDataTabSemFd); -// sem_close(poolDataTabSemFd); // deverouiller semaphore ressource. msgPoolSemIdIntern(ressourceSemId,space->id,poolIndex); diff --git a/test/put_get.c b/test/put_get.c index ce4b3b7..5920e0f 100644 --- a/test/put_get.c +++ b/test/put_get.c @@ -26,24 +26,18 @@ int main(void) { } printf("CREATION ------------------ ok\n"); - sleep(1); - pid_t pid=fork(); - - if (pid ==0){ - mSPAC=msgSpaceOpen(testId); - sleep(2); - printf("Get..."); fflush(stdout); - montext=msgGet(mSPAC,0,0); - printf("get-ok\n"); - } else { - mSPAC=msgSpaceOpen(testId); - montext=msgAllocate(mSPAC,2,280,0); - *montext=42; - printf("### test Valeur0 %d ###\n",(int)*montext); - printf("Put..."); fflush(stdout); - msgPut(mSPAC,0,montext); - printf("put-ok\n"); - //sleep(2); - } + + mSPAC=msgSpaceOpen(testId); + montext=msgAllocate(mSPAC,2,280,0); + *montext=42; + printf("### test Valeur0 %d ###\n",(int)*montext); + printf("Put..."); fflush(stdout); + msgPut(mSPAC,0,montext); + printf("put-ok\n"); + + + printf("Get..."); fflush(stdout); + montext=msgGet(mSPAC,0,0); + printf("get-ok\n"); return 0; }