From 6d2950ac6bd83fbdbd5553231a28bd179dc1ad78 Mon Sep 17 00:00:00 2001 From: glenux Date: Mon, 23 Feb 2004 10:33:14 +0000 Subject: [PATCH] *** empty log message *** --- src/nzg_msgList.c | 82 ------------------------------------------- src/nzg_spaceCreate.c | 24 ++++++++++--- test/create_delete.c | 8 +---- 3 files changed, 20 insertions(+), 94 deletions(-) delete mode 100644 src/nzg_msgList.c diff --git a/src/nzg_msgList.c b/src/nzg_msgList.c deleted file mode 100644 index 92503bb..0000000 --- a/src/nzg_msgList.c +++ /dev/null @@ -1,82 +0,0 @@ -/*void *add(char * idAncien, char *idNouveau); - int descMemory; - - void * add(char * idAncien, char *idNouveau){ - descMemory=shm_open("/titi", - O_RDWR|O_CREAT|O_EXCL|O_TRUNC, - 0600); - - if (descMemory== -1){ - printf("erreur de sh_open\n"); - return NULL; - }; - - if (ftruncate(descMemory,1024)== -1 ){ - printf("erreur ftruncate"); - } - - memory= mmap(0, 1024, - PROT_READ | PROT_WRITE, - - - MAP_SHARED, mSFd, 0)*/ -/*typedef struct MsgSpaceListElem { - void * id; - int ownerPid; - msgSpaceListElemId next; - } * msgSpaceList, msgSpaceListElem; - - msgSpaceListElemId *mslist; - - if( Strcpy(idAncien, idNouveau) ==-1){ - printf("erreur de strcpy"); - }; - - strcpy(idAncien, idNouveau); - return NULL; - - } - */ - - - - - - - - - - - -/* ajout dans la liste */ -/*AVEC POINTEUR */ -/* - msgSpaceListElem *addBegining( msgSpaceListElem*list,int ownerpid){ - msgSpaceListElem *unSpacemsgListElem; - if( (unSpacemsgListElem=(msgSpaceListElem *)malloc(sizeof(msgSpaceListElem) ) )==NULL){ - perror("ereur dallocation de memoire"); - exit(1);} - unSpacemsgListElem->ownerPid = ownerpid; - return(unSpacemsgListElem); - - } - - - - - - int test(int argc,char **argv){ - msgSpaceListElem *ma_liste; - msgSpaceListElem *listMove; - ma_liste=NULL; - ma_liste=addBegining(ma_liste, 3); - ma_liste=addBegining(ma_liste, 6); - ma_liste=addBegining(ma_liste, 5); - for (listMove=ma_liste ;listMove!=NULL ; listMove=listMove->next) - { - printf("valaeur :%d\n",listMove->ownerPid); - } - return(0); - } - */ - diff --git a/src/nzg_spaceCreate.c b/src/nzg_spaceCreate.c index 215843b..cd01fa3 100644 --- a/src/nzg_spaceCreate.c +++ b/src/nzg_spaceCreate.c @@ -4,7 +4,8 @@ /* prototypes des fonctions annexes à ne pas exporter */ int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src ); int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src ); - +int msgPoolDataTabSemIdIntern( + msgPoolSemId destSemId,const msgSpaceId externId); /* * spaceId : identifiant externe de l'espace de msg * queueNb : nombre de files de messages @@ -29,7 +30,7 @@ msgSpace * msgSpaceCreate( msgPoolData * mSPoolDataAddr; msgBufferInfoTabId bufferInfoTabId; msgPoolId poolId; - + sem_t * mSDataTabSemFd; mSIdNum++; mSAddr=NULL; @@ -79,11 +80,23 @@ msgSpace * msgSpaceCreate( mSAddr->poolNb=poolNb; mSAddr->queueNb=queueNb; mSAddr->pid=getpid(); - + msgPoolDataTabSemIdIntern(mSAddr->poolDataTabSemId,externId); /* creation du poolData */ msgPoolDataIdIntern(poolDataTabId,externId); strcpy(mSAddr->poolDataTabId,poolDataTabId); + mSDataTabSemFd=sem_open(mSAddr->poolDataTabSemId, + O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + if (mSDataTabSemFd == SEM_FAILED){ + NZG_ERROR("sem_open : creation de la ressource", + mSAddr->poolDataTabSemId); + return NULL; + } else { + NZG_ERROR("sem_open : creation oki", + mSAddr->poolDataTabSemId); + } + sem_wait(mSDataTabSemFd); + mSPoolDataFd=shm_open( poolDataTabId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, @@ -133,9 +146,9 @@ msgSpace * msgSpaceCreate( printf("buffIfoTab %d name : %s\n",i,mSPoolDataAddr[i].bufferInfoTabId); msgBufferInfoTabCreate(externId,mSPoolDataAddr,i,poolInfos[i].bufferNb); - if (msgPoolIdIntern(poolId,externId,i) == -1){ + if (msgPoolIdIntern(poolId,externId,i) == -1){ fprintf( stderr, "msgPoolId creation failed for id %s\n", - (char*)poolId ); + (char*)poolId ); return NULL; } strcpy(mSPoolDataAddr[i].id,poolId); @@ -146,6 +159,7 @@ msgSpace * msgSpaceCreate( /* TODO: on ajoute spaceId a la liste des msgSpace connus */ /* TODO: on crée queueNb files de messages */ /* on renvoie un pointeur sur le bon spaceId */ + sem_post(mSDataTabSemFd); return mSAddr; } diff --git a/test/create_delete.c b/test/create_delete.c index 5972bdf..cc60885 100644 --- a/test/create_delete.c +++ b/test/create_delete.c @@ -15,7 +15,7 @@ int main(void) { poolInfos[1].bufferNb=5; poolInfos[1].bufferSize=250; - poolInfos[2].bufferNb=3; + poolInfos[2].bufferNb=6; poolInfos[2].bufferSize=280; strcpy(testId,"test"); @@ -31,24 +31,18 @@ int main(void) { mSPAC=msgSpaceOpen(testId); sleep(2); montext=msgAllocate(mSPAC,2,180,0); - printf("ALLOC %d.. ok\n",(int)getpid()); sleep(2); montext=msgAllocate(mSPAC,2,170,0); - printf("ALLOC %d.. ok\n",(int)getpid()); sleep(2); montext=msgAllocate(mSPAC,2,270,0); - printf("ALLOC %d.. ok\n",(int)getpid()); } else { mSPAC=msgSpaceOpen(testId); montext=msgAllocate(mSPAC,2,280,0); - printf("ALLOC %d.. ok\n",(int)getpid()); sleep(2); montext=msgAllocate(mSPAC,2,270,0); - printf("ALLOC %d.. ok\n",(int)getpid()); sleep(2); montext=msgAllocate(mSPAC,2,270,0); - printf("ALLOC %d.. ok\n",(int)getpid()); //msgFree(mSPAC,(void *)montext); //msgFree(mSPAC,(void *)montext); //msgFree(mSPAC,(void *)montext);