From 1007ca56c6498319c871ea8cd80ce03d7d1bd834 Mon Sep 17 00:00:00 2001 From: glenux Date: Mon, 23 Feb 2004 15:54:29 +0000 Subject: [PATCH] *** empty log message *** --- src/nzg_allocate.c | 2 +- src/nzg_bufferDetachProc.c | 2 +- src/nzg_free.c | 80 ++++++++++++++++++++++++++++++++++++++ src/nzg_proto.h | 8 +++- 4 files changed, 89 insertions(+), 3 deletions(-) diff --git a/src/nzg_allocate.c b/src/nzg_allocate.c index 040c95c..6603578 100644 --- a/src/nzg_allocate.c +++ b/src/nzg_allocate.c @@ -38,7 +38,7 @@ void * msgAllocate(msgSpace *space, - /* TODO: verifier le premier arg du shm_open */ + /* verifier le premier arg du shm_open */ mSPoolDataTabFd=shm_open(space->poolDataTabId, O_RDWR, MSGSPACE_DEFAULT_MODE); diff --git a/src/nzg_bufferDetachProc.c b/src/nzg_bufferDetachProc.c index 5b1572e..8ec4949 100644 --- a/src/nzg_bufferDetachProc.c +++ b/src/nzg_bufferDetachProc.c @@ -1,7 +1,7 @@ #include "libnazgul.h" int msgBufferDetachProc( - msgPoolData * poolDataTabAddr, + msgPoolData * poolDataTabAddr, int poolIndex, int bufferIndex, void * addr diff --git a/src/nzg_free.c b/src/nzg_free.c index b99a2f6..ecd9b9a 100644 --- a/src/nzg_free.c +++ b/src/nzg_free.c @@ -1,6 +1,86 @@ #include "libnazgul.h" int msgFree(msgSpace * space, void * addr){ + + int poolIndex; + int bufferIndex; + int poolDataTabFd; + msgPoolData * poolDataTabAddr; +sem_t * poolDataTabSemFd; + msgPoolDataTabSemId ressourceSemId; + sem_t * ressourceSemFd; + /* 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); + + + + /* verifier le premier arg du shm_open */ + + poolDataTabFd=shm_open(space->poolDataTabId, + O_RDWR, + MSGSPACE_DEFAULT_MODE); + if (poolDataTabFd == -1 ) { + fprintf( stderr, "Allocate %s failed: %s\n", + (char*)space->poolDataTabId, + strerror( errno ) ); + return -1; + } + + + poolDataTabAddr = mmap( 0, (space->poolNb) * sizeof( msgPoolData ), + PROT_READ | PROT_WRITE, + MAP_SHARED, poolDataTabFd, 0 ); + + if( poolDataTabAddr == MAP_FAILED) { + fprintf( stderr, "mmap failed: %s\n", + strerror( errno ) ); + return -1; + } + + + // TODO: verouiller semaphore DataInfo + int err; + + err=msgBufferGetProcAttach( + poolDataTabAddr, + space->poolNb, + &poolIndex, + &bufferIndex, + addr + ); + + msgBufferDetachProc(poolDataTabAddr,poolIndex,bufferIndex,addr); + + /* unmapper le msgPoolDataTab */ + munmap(poolDataTabAddr,(space->poolNb) * sizeof( msgPoolData )); + + close(poolDataTabFd); + + // deverouiller semaphore DataInfo + sem_post(poolDataTabSemFd); + sem_close(poolDataTabSemFd); + + // deverouiller semaphore ressource. + msgPoolSemIdIntern(ressourceSemId,space->id,poolIndex); + ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0); + if (ressourceSemFd == SEM_FAILED){ + NZG_ERROR("sem_open",ressourceSemId); + return -1; + } + sem_post(ressourceSemFd); + sem_close(ressourceSemFd); + + //sem_open ressource + //sem_post + //sem_close return -1; } diff --git a/src/nzg_proto.h b/src/nzg_proto.h index f0ddab3..b4f40c3 100644 --- a/src/nzg_proto.h +++ b/src/nzg_proto.h @@ -40,5 +40,11 @@ int msgSpaceDelete(msgSpaceId externId); /* nzg_spaceOpen.c */ msgSpace *msgSpaceOpen(msgSpaceId externId); /* nzg_state.c */ - +int msgBufferGetProcAttach( + msgPoolData * poolDataTabAddr, + int poolNb, + int * poolIndex, + int * bufferIndex, + void * addr + ); #endif