From 3d75566a88b9e5ea28cb1faff1ce961dd449764c Mon Sep 17 00:00:00 2001 From: glenux Date: Sun, 7 Mar 2004 12:26:42 +0000 Subject: [PATCH] *** empty log message *** --- src/allocate.c | 2 +- src/bufferGetProcAttach.c | 3 ++- src/free.c | 23 +++++++++++++---------- src/get.c | 2 +- src/global.h | 5 +++++ src/poolDataTabLock.c | 12 +++++++----- src/poolDataTabUnlock.c | 4 +++- src/put.c | 12 ++++++------ src/queueDelete.c | 4 ++-- src/queueElemCreate.c | 2 +- test/Makefile | 9 +++++++-- test/create_delete.c | 7 ++++++- test/msgSpaceState.c | 5 +++++ test/put_get_mono.c | 7 ++++++- test/put_get_multi.c | 7 ++++++- 15 files changed, 71 insertions(+), 33 deletions(-) diff --git a/src/allocate.c b/src/allocate.c index 5fdb8b9..f74a8fb 100644 --- a/src/allocate.c +++ b/src/allocate.c @@ -15,6 +15,7 @@ void * msgAllocate(msgSpace *space, int option ){ void * resultAddr=NULL; + int bufferFreeSize; int i; msgPoolId resultPoolId; /* tableau des valeurs des semPoolCoef/pool pour identifier le pool @@ -183,7 +184,6 @@ if (mSPoolDataTabAddr==NULL){ /* mapper le buffer libre dans l'esp addr du proc */ strcpy(resultPoolId,mSPoolDataTabAddr[selectedPoolIndex].poolId); - int bufferFreeSize; bufferFreeSize=mSPoolDataTabAddr[selectedPoolIndex].bufferSize; printf("BufferSize : %d\n", bufferFreeSize); diff --git a/src/bufferGetProcAttach.c b/src/bufferGetProcAttach.c index a95de11..0919f1f 100644 --- a/src/bufferGetProcAttach.c +++ b/src/bufferGetProcAttach.c @@ -14,6 +14,7 @@ int msgBufferGetProcAttach( bool found=false; int pIdx=0; + int bIdx; while ((!found) && (pIdx < poolNb)){ /* Pour chaque pool */ //récuperer l'ID du BufferInfoTab; @@ -29,7 +30,7 @@ int msgBufferGetProcAttach( PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); /* on cherche dans chacun des buffers */ - int bIdx=0; + bIdx=0; while((!found) && bIdxpoolDataTabSemId); @@ -20,7 +24,6 @@ int msgFree(msgSpace * space, void * addr){ poolDataTabAddr = msgPoolDataTabOpen(space); // TODO: verouiller semaphore DataInfo ?? - int err; poolIndex=-1; bufferIndex=-1; err=msgBufferGetProcAttach( @@ -36,17 +39,17 @@ int msgFree(msgSpace * space, void * addr){ msgBufferDetachProc(poolDataTabAddr,poolIndex,bufferIndex,addr); /* unmapper le buffer */ - void * realAddr=addr; - int bufferSize=poolDataTabAddr[poolIndex].bufferSize; - int bufferNb=poolDataTabAddr[poolIndex].bufferNb; + realAddr=addr; + bufferSize=poolDataTabAddr[poolIndex].bufferSize; + bufferNb=poolDataTabAddr[poolIndex].bufferNb; realAddr=realAddr-poolIndex*bufferSize; munmap(realAddr,bufferSize*bufferNb); - + msgPoolDataTabClose(space,poolDataTabAddr); // deverouiller semaphore DataInfo -msgPoolDataTabUnlock(space); - + msgPoolDataTabUnlock(space); + // deverouiller semaphore ressource. msgPoolSemIdIntern(ressourceSemId,space->externId,poolIndex); ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0); diff --git a/src/get.c b/src/get.c index 0ecdec7..0fd0306 100644 --- a/src/get.c +++ b/src/get.c @@ -8,6 +8,7 @@ void * msgGet(msgSpace * space,int queueIndex,int option){ msgQueue * queue; msgQueueElemId oldElemId; msgQueueElem * oldElem; + msgPoolData * poolDataTab; // on teste la possibilité de lecture sur la liste... if (option == NONBLOCK){ if (msgQueueReadTryLock(space->externId,queueIndex) <0){ @@ -39,7 +40,6 @@ void * msgGet(msgSpace * space,int queueIndex,int option){ goto ERROR; } /* on récupere la taille des buffer dans la pool du buffer */ - msgPoolData * poolDataTab; poolDataTab=msgPoolDataTabOpen(space); // mapper le buffer dans l'espace mémoire du processus resultAddr=msgBufferMap(poolDataTab,oldElem->poolIndex,oldElem->bufferIndex); diff --git a/src/global.h b/src/global.h index ad6fe15..7843fa7 100644 --- a/src/global.h +++ b/src/global.h @@ -26,6 +26,11 @@ #endif +#ifndef MAP_FAILED +#define MAP_FAILED ((void *)-1) +#endif + + #ifdef _NZG_REALFILEID #define DEFAULT_MSGSPACELISTID "/tmp/nzgSpaceList" #else diff --git a/src/poolDataTabLock.c b/src/poolDataTabLock.c index a8790cd..fc4b633 100644 --- a/src/poolDataTabLock.c +++ b/src/poolDataTabLock.c @@ -4,10 +4,12 @@ #define DEBUG 0 int msgPoolDataTabLock(msgSpace * space){ + int semval; sem_t * poolDataTabSemFd; -if (DEBUG) {printf("Locking %s\n",space->poolDataTabSemId);} + semval=0; + if (DEBUG) {printf("Locking %s\n",space->poolDataTabSemId);} - poolDataTabSemFd=sem_open( + poolDataTabSemFd=sem_open( space->poolDataTabSemId ,O_CREAT, SEM_DEFAULT_MODE, @@ -21,9 +23,9 @@ if (DEBUG) {printf("Locking %s\n",space->poolDataTabSemId);} NZG_ERROR("sem_wait",space->poolDataTabSemId); goto ERROR; } - int semval=0; - sem_getvalue(poolDataTabSemFd,&semval); - if (DEBUG) { printf("(AfternValue:%d)\n",semval);} + + sem_getvalue(poolDataTabSemFd,&semval); + if (DEBUG) { printf("(AfternValue:%d)\n",semval);} sem_close(poolDataTabSemFd); diff --git a/src/poolDataTabUnlock.c b/src/poolDataTabUnlock.c index 4c9afdc..e976f4e 100644 --- a/src/poolDataTabUnlock.c +++ b/src/poolDataTabUnlock.c @@ -4,6 +4,7 @@ #define DEBUG 0 int msgPoolDataTabUnlock(msgSpace * space){ + int semval; sem_t * poolDataTabSemFd; if (DEBUG) { printf("Unlocking %s\n",space->poolDataTabSemId); } poolDataTabSemFd=sem_open( @@ -20,7 +21,8 @@ int msgPoolDataTabUnlock(msgSpace * space){ NZG_ERROR("sem_post",space->poolDataTabSemId); goto ERROR; } - int semval=0; + + semval=0; sem_getvalue(poolDataTabSemFd,&semval); if (DEBUG) { printf("(AfternValue:%d)\n",semval); } diff --git a/src/put.c b/src/put.c index f92a0a2..b3ee344 100644 --- a/src/put.c +++ b/src/put.c @@ -6,8 +6,10 @@ int msgPut(msgSpace * space,int queueIndex, void * addr){ int poolIndex; int bufferIndex; int err; - msgQueueElemId newElemId; + msgQueueElemId newElemId; msgQueueElem * queueElem; + msgQueueId queueId; + msgQueue * queue; msgPoolDataTabLock(space); poolDataTabAddr=msgPoolDataTabOpen(space); @@ -24,15 +26,13 @@ int msgPut(msgSpace * space,int queueIndex, void * addr){ ); // ouvrir la queue avec le bon index - msgQueueId queueId; - msgQueue * queue; msgQueueIdIntern(queueId,space->externId,queueIndex); - + msgQueueProtLock(space->externId,queueIndex); queue = msgQueueOpen(queueId); // creer un element vide - + msgQueueElemCreate(newElemId,queueId,queue->elemCounter); // ouvrir l'element queueElem=msgQueueElemOpen(newElemId); @@ -40,7 +40,7 @@ int msgPut(msgSpace * space,int queueIndex, void * addr){ // modifier les index pour retrouver le buffer queueElem->poolIndex=poolIndex; queueElem->bufferIndex=bufferIndex; - + // fermer l'element if (msgQueueElemClose(queueElem) <0 ){ NZG_ERROR("msgQueueElemClose",""); diff --git a/src/queueDelete.c b/src/queueDelete.c index b6ff4d3..eddcc86 100644 --- a/src/queueDelete.c +++ b/src/queueDelete.c @@ -3,6 +3,8 @@ int msgQueueDelete(msgQueueId externId,int queueIdx){ msgQueue * queue; msgQueueId queueId; + msgQueueSemId queueProtLockSemId; + msgQueueSemId queueReadLockSemId; msgQueueIdIntern(queueId,externId,queueIdx); queue = msgQueueOpen(queueId); @@ -15,8 +17,6 @@ int msgQueueDelete(msgQueueId externId,int queueIdx){ } } - msgQueueSemId queueProtLockSemId; - msgQueueSemId queueReadLockSemId; msgQueueProtSemIdIntern(queueProtLockSemId,externId,queueIdx); msgQueueReadSemIdIntern(queueReadLockSemId,externId,queueIdx); sem_unlink(queueProtLockSemId); diff --git a/src/queueElemCreate.c b/src/queueElemCreate.c index 62769d9..b127d1f 100644 --- a/src/queueElemCreate.c +++ b/src/queueElemCreate.c @@ -6,11 +6,11 @@ int msgQueueElemCreate( msgQueueId queueId, int counter){ msgQueueElemId queueElemId; + int queueElemFd; msgQueueElemIdIntern(queueElemId,queueId,counter); strcpy(finalQueueElemId,queueElemId); - int queueElemFd; queueElemFd=shm_open(queueElemId, O_RDWR|O_CREAT|O_EXCL|O_TRUNC, SHM_DEFAULT_MODE); diff --git a/test/Makefile b/test/Makefile index fa41474..755cdf9 100644 --- a/test/Makefile +++ b/test/Makefile @@ -24,21 +24,26 @@ CC=gcc CFLAGS=-Wall -O2 -ggdb #-O2 -ggdb -INCLUDES=-I /usr/include/ -I /usr/include/sys -I ../src/ +INCLUDES=-I /usr/include/ -I ../src/ LIBINC=-L /usr/lib -L ../src BASELIBS=-lnazgul LIBS=$(BASELIBS) +DEFS= + ifeq "HP-UX" "${OS}" + DEFS=-D_NZG_HPUX LIBS=$(BASELIBS) -lpthread -lrt endif ifeq "SunOS" "${OS}" + DEFS=-D_NZG_SUNOS LIBS=$(BASELIBS) -lrt endif ifeq "Linux" "${OS}" + DEFS=-D_NZG_LINUX LIBS=$(BASELIBS) -lrt -lpthread endif @@ -61,7 +66,7 @@ clean: @rm -f $(FILES) % : %.c - $(CC) -o $* $< $(INCLUDES) $(LIBINC) $(LIBS) $(CFLAGS) + $(CC) -o $* $< $(INCLUDES) $(LIBINC) $(LIBS) $(CFLAGS) $(DEFS) edit: gvim *.h *.c diff --git a/test/create_delete.c b/test/create_delete.c index 33b3aa2..071e3e6 100644 --- a/test/create_delete.c +++ b/test/create_delete.c @@ -1,4 +1,9 @@ +#ifdef _NZG_HPUX +#include +#else #include +#endif + #include "libnazgul.h" int main(void) { @@ -20,7 +25,7 @@ int main(void) { sprintf(testId,"test%d",(int)getuid()); printf("RequestedId: %s\n",testId); - printf("Void size: %d\n",sizeof(void)); + printf("Void size: %d\n",(int)sizeof(void)); mSPAC=msgSpaceCreate(testId,0,3,poolInfos); if (mSPAC ==NULL) { NZG_ERROR("msgSpaceCreate",testId); diff --git a/test/msgSpaceState.c b/test/msgSpaceState.c index 14a62ab..68ca16d 100644 --- a/test/msgSpaceState.c +++ b/test/msgSpaceState.c @@ -1,4 +1,9 @@ +#ifdef _NZG_HPUX +#include +#else #include +#endif + #include "libnazgul.h" void usage(char * myname){ diff --git a/test/put_get_mono.c b/test/put_get_mono.c index d450df4..e10715c 100644 --- a/test/put_get_mono.c +++ b/test/put_get_mono.c @@ -1,4 +1,9 @@ +#ifdef _NZG_HPUX +#include +#else #include +#endif + #include "libnazgul.h" int main(void) { @@ -17,7 +22,7 @@ int main(void) { sprintf(testId,"test%d",(int)getuid()); printf("RequestedId: %s\n",testId); - printf("Void size: %d\n",sizeof(void)); + printf("Void size: %d\n",(int)sizeof(void)); //creation de l'espace de messages mSPAC=msgSpaceCreate(testId,1,2,poolInfos); if (mSPAC ==NULL) { diff --git a/test/put_get_multi.c b/test/put_get_multi.c index f23a5eb..d541214 100644 --- a/test/put_get_multi.c +++ b/test/put_get_multi.c @@ -1,4 +1,9 @@ +#ifdef _NZG_HPUX +#include +#else #include +#endif + #include "libnazgul.h" int main(void) { @@ -17,7 +22,7 @@ int main(void) { sprintf(testId,"test%d",(int)getuid()); printf("RequestedId: %s\n",testId); - printf("Void size: %d\n",sizeof(void)); + printf("Void size: %d\n",(int)sizeof(void)); //creation de l'espace de messages mSPAC=msgSpaceCreate(testId,1,2,poolInfos); if (mSPAC ==NULL) {