From 1580be12cd1edb46c6a1d3108e97530776a88eb1 Mon Sep 17 00:00:00 2001 From: glenux Date: Sun, 22 Feb 2004 18:09:05 +0000 Subject: [PATCH] *** empty log message *** --- src/nzg_allocate.c | 16 +++++++++++----- src/nzg_bufferInfoTabInit.c | 1 - test/create_delete.c | 4 ++-- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/nzg_allocate.c b/src/nzg_allocate.c index 8e1efd9..9becc5a 100644 --- a/src/nzg_allocate.c +++ b/src/nzg_allocate.c @@ -7,6 +7,7 @@ */ +/* TODO: prevoir le cas des négatifs dans la taille ... */ void * msgAllocate(msgSpace *space, int pool, @@ -24,7 +25,7 @@ void * msgAllocate(msgSpace *space, sem_t * poolDataTabSemFd=NULL; msgPoolDataTabSemId ressourceSemId; sem_t * ressourceSemFd=NULL; - int * ressourceSemVal=NULL; + int ressourceSemVal; float minPoolCoef; int selectedPoolIndex; int bufferFreeIndex; @@ -63,9 +64,12 @@ void * msgAllocate(msgSpace *space, int nbLockedSem=0; if ( pool == ANYPOOL){ + fprintf(stderr,">>>> ANYPOOL selection <<<<\n"); // choisir le pool au hasard (ou presque) for(i=0; i<(space->poolNb); i++) { + printf("ERRORDETECT boucle %d\n",i); fflush(stdout); if(mSPoolDataTabAddr[i].bufferSize >= taille) { + printf("ERRORDETECT buffS > taill %d\n",i); fflush(stdout); /* choisir le numero du semaphore en fonction du nombre de lock poses / nombre de buffer */ msgPoolSemIdIntern(ressourceSemId,space->id,i); @@ -76,18 +80,18 @@ void * msgAllocate(msgSpace *space, } /* on remplit le tableau avec les valeurs des semaphores */ - if (sem_getvalue(ressourceSemFd, ressourceSemVal) < 0){ + if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){ NZG_ERROR("sem_getvalue",ressourceSemId); return NULL; } - if ((*ressourceSemVal) < 0){ + if ((ressourceSemVal) < 0){ /* il y a ressourceSemVal processus qui attendent déja... */ semPoolCoef[nbLockedSem] = - (float) (- (*ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb); + (float) (- (ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb); nbLockedSem++; } - if(sem_trywait(ressourceSemFd)) { + if(sem_trywait(ressourceSemFd)==0) { /* choisir la 1ere pool de taille plus grande * libre si possible */ gotRessourceSem=true; @@ -101,6 +105,8 @@ void * msgAllocate(msgSpace *space, } // if buffSize > taille } // for + printf("ERRORDETECT\n"); fflush(stdout); + if (!gotRessourceSem) { minPoolCoef= semPoolCoef[0]; idxPoolOptimum = 0; diff --git a/src/nzg_bufferInfoTabInit.c b/src/nzg_bufferInfoTabInit.c index 2d3e373..12d9f6c 100644 --- a/src/nzg_bufferInfoTabInit.c +++ b/src/nzg_bufferInfoTabInit.c @@ -20,7 +20,6 @@ int bufferInfoNb; bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), PROT_WRITE|PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); - printf("fd ?\n"); fflush(stdout); int i; for (i=0;i