From 3909693db4f4b6e5cc3805a54190ce1e1b9b370b Mon Sep 17 00:00:00 2001 From: glenux Date: Mon, 23 Feb 2004 12:28:31 +0000 Subject: [PATCH] *** empty log message *** --- src/nzg_allocate.c | 31 ++++++++++++++++++------------- src/nzg_bufferAttachProc.c | 4 +++- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/src/nzg_allocate.c b/src/nzg_allocate.c index a49cd2c..cd1fc77 100644 --- a/src/nzg_allocate.c +++ b/src/nzg_allocate.c @@ -37,14 +37,7 @@ void * msgAllocate(msgSpace *space, selectedPoolIndex=-1; - 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 NULL; - } - sem_wait(poolDataTabSemFd); - + /* TODO: verifier le premier arg du shm_open */ mSPoolDataTabFd=shm_open(space->poolDataTabId, O_RDWR, @@ -171,7 +164,15 @@ void * msgAllocate(msgSpace *space, /* on a acqui un semaphore pour la ressouce */ /* on acquiert le droit de modifier les infos sur la ressource */ - //sem_wait(poolDataTabSemFd); + /* 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 NULL; + } + sem_wait(poolDataTabSemFd); /* on modifie maintenant les données */ /* - on récupere l'index du premier buffer libre */ @@ -186,17 +187,21 @@ void * msgAllocate(msgSpace *space, /* mapper le buffer libre dans l'esp addr du proc */ strcpy(resultPoolId,mSPoolDataTabAddr[selectedPoolIndex].poolId); + mSPoolFd=shm_open(resultPoolId,O_RDWR,MSGSPACE_DEFAULT_MODE); - + resultAddr = mmap( 0, mSPoolDataTabAddr[selectedPoolIndex].bufferSize, PROT_READ | PROT_WRITE, MAP_SHARED, mSPoolFd, 0 ); - + //TODO: /* - on s'enregistre aupres de ce buffer */ - //msgBufferAttachProc(mSPoolDataTabFd,selectedPoolIndex,resultAddr); - + msgBufferAttachProc(mSPoolDataTabAddr, + selectedPoolIndex, + bufferFreeIndex, + resultAddr); + close(mSPoolFd); sem_post(poolDataTabSemFd); sem_close(poolDataTabSemFd); diff --git a/src/nzg_bufferAttachProc.c b/src/nzg_bufferAttachProc.c index 9f83c90..9f1b976 100644 --- a/src/nzg_bufferAttachProc.c +++ b/src/nzg_bufferAttachProc.c @@ -14,6 +14,7 @@ int msgBufferAttachProc( //récuperer l'ID du BufferInfoTab; strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); if (bufferInfoTabFd<0){ NZG_ERROR("sem_open",bufferInfoTabId); @@ -23,7 +24,8 @@ int msgBufferAttachProc( /** on regarde dans le tableau d'infos de buffer **/ bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), - PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + PROT_READ|PROT_WRITE,MAP_SHARED,bufferInfoTabFd,(off_t)0); + printf("atta gooo %s\n",bufferInfoTabId); bufferInfoTabAddr[bufferIndex].ownerPid = getpid(); bufferInfoTabAddr[bufferIndex].addr = addr;