From 8ee07b027e374f8833138a9c1b394be6ac76769a Mon Sep 17 00:00:00 2001 From: glenux Date: Mon, 23 Feb 2004 11:02:15 +0000 Subject: [PATCH] *** empty log message *** --- src/nzg_allocate.c | 37 ++++++++++++++++++++++++++----------- src/nzg_iface.h | 2 +- src/nzg_spaceCreate.c | 2 +- 3 files changed, 28 insertions(+), 13 deletions(-) diff --git a/src/nzg_allocate.c b/src/nzg_allocate.c index 56e611b..9b29922 100644 --- a/src/nzg_allocate.c +++ b/src/nzg_allocate.c @@ -22,9 +22,9 @@ void * msgAllocate(msgSpace *space, float semPoolCoef[space->poolNb]; int idxPoolOptimum; bool gotRessourceSem; - sem_t * poolDataTabSemFd=NULL; + sem_t * poolDataTabSemFd; msgPoolDataTabSemId ressourceSemId; - sem_t * ressourceSemFd=NULL; + sem_t * ressourceSemFd; int ressourceSemVal; float minPoolCoef; int selectedPoolIndex; @@ -32,6 +32,15 @@ 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, @@ -67,9 +76,9 @@ void * msgAllocate(msgSpace *space, fprintf(stderr,"[ ALLOCATION ANYPOOL : %d ]\n",(int)getpid()); // choisir le pool au hasard (ou presque) for(i=0; i<(space->poolNb); i++) { - printf("ERRORDETECT boucle %d\n",i); fflush(stdout); + printf("- boucle %d\n",i); fflush(stdout); if(mSPoolDataTabAddr[i].bufferSize >= taille) { - printf("ERRORDETECT buffS > taill %d\n",i); fflush(stdout); + printf("( buffSize > taille )\n"); fflush(stdout); /* choisir le numero du semaphore en fonction du nombre de lock poses / nombre de buffer */ msgPoolSemIdIntern(ressourceSemId,space->id,i); @@ -138,7 +147,6 @@ void * msgAllocate(msgSpace *space, } if (!gotRessourceSem){ - strcpy(resultPoolId,mSPoolDataTabAddr[selectedPoolIndex].id); msgPoolSemIdIntern(ressourceSemId,space->id,selectedPoolIndex); ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0); if(ressourceSemFd==SEM_FAILED){ @@ -160,9 +168,6 @@ void * msgAllocate(msgSpace *space, /* on a acqui un semaphore pour la ressouce */ /* on acquiert le droit de modifier les infos sur la ressource */ - - poolDataTabSemFd=sem_open(space->poolDataTabSemId,O_CREAT,SEM_DEFAULT_MODE,1); - printf("VOILAAA : %s\n",space->poolDataTabSemId); //sem_wait(poolDataTabSemFd); /* on modifie maintenant les données */ @@ -174,13 +179,23 @@ void * msgAllocate(msgSpace *space, return NULL; } printf("Buffer selected : %d,%d\n",selectedPoolIndex,bufferFreeIndex); - /*TODO: mapper le buffer libre dans l'esp addr du proc */ + + /* mapper le buffer libre dans l'esp addr du proc */ + strcpy(resultPoolId,mSPoolDataTabAddr[selectedPoolIndex].poolId); + + int 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 */ - //TODO: msgBufferAttachProc(space,selectedPoolIndex,resultAddr); + //msgBufferAttachProc(mSPoolDataTabFd,selectedPoolIndex,resultAddr); - // sem_post(poolDataTabSemFd); + sem_post(poolDataTabSemFd); sem_close(poolDataTabSemFd); /* TODO: unmapper le msgPoolDataTab */ diff --git a/src/nzg_iface.h b/src/nzg_iface.h index c72c3cb..cdc2864 100644 --- a/src/nzg_iface.h +++ b/src/nzg_iface.h @@ -35,7 +35,7 @@ typedef struct MsgBufferInfo { } msgBufferInfo; typedef struct MsgPoolData { - msgPoolId id; + msgPoolId poolId; msgBufferInfoTabId bufferInfoTabId; int bufferNb; int bufferSize; diff --git a/src/nzg_spaceCreate.c b/src/nzg_spaceCreate.c index cd01fa3..852217b 100644 --- a/src/nzg_spaceCreate.c +++ b/src/nzg_spaceCreate.c @@ -151,7 +151,7 @@ msgSpace * msgSpaceCreate( (char*)poolId ); return NULL; } - strcpy(mSPoolDataAddr[i].id,poolId); + strcpy(mSPoolDataAddr[i].poolId,poolId); msgPoolCreate(externId,i,poolInfos[i].bufferNb,poolInfos[i].bufferSize); }