*** empty log message ***

This commit is contained in:
glenux 2004-02-22 21:53:50 +00:00
parent 9859ee41ac
commit 5eeb283e70
8 changed files with 62 additions and 33 deletions

View file

@ -45,6 +45,16 @@ clean:
%.o : %.c
@echo -e "$(CC)\t$@"
@$(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) $(DEFINES) -o $*.o
protos: $(CFILES)
@rm -f nzg_proto.h
@touch nzg_proto.h
@( echo -e "#ifndef _NZG_PROTO"; \
echo -e "#define _NZG_PROTO 1\n"; \
cproto *.c ; \
echo -e "\n#endif") > nzg_proto.t
@mv nzg_proto.t nzg_proto.h
edit:
gvim *.c *.h

View file

@ -29,7 +29,7 @@ void * msgAllocate(msgSpace *space,
float minPoolCoef;
int selectedPoolIndex;
int bufferFreeIndex;
selectedPoolIndex=-1;
/* TODO: verifier le premier arg du shm_open */
@ -55,16 +55,16 @@ void * msgAllocate(msgSpace *space,
return NULL;
}
gotRessourceSem=false;
gotRessourceSem=false;
/* initialisation des coefs */
for (i=0;i<(space->poolNb);i++){
semPoolCoef[i]=-1;
}
int nbLockedSem=0;
if ( pool == ANYPOOL){
fprintf(stderr,">>>> ANYPOOL selection <<<<\n");
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);
@ -79,40 +79,44 @@ void * msgAllocate(msgSpace *space,
return NULL;
}
/* on remplit le tableau avec les valeurs des semaphores */
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL;
}
if ((ressourceSemVal) < 0){
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL;
}
printf("RESSOURCESEMVAL %d\n",ressourceSemVal);
if (ressourceSemVal <= 0){
printf("resVal < 0 : %d\n",ressourceSemVal);
/* il y a ressourceSemVal processus qui attendent déja... */
semPoolCoef[nbLockedSem] =
(float) (- (ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb);
nbLockedSem++;
}
if(sem_trywait(ressourceSemFd)==0) {
printf("got try_wait\n");
/* choisir la 1ere pool de taille plus grande
* libre si possible */
gotRessourceSem=true;
selectedPoolIndex=i;
break;
}
if( sem_close(ressourceSemFd) <0){
NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL;
}
if( sem_close(ressourceSemFd) <0){
NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL;
}
} // if buffSize > taille
} // for
printf("ERRORDETECT\n"); fflush(stdout);
printf("ERRORDETECT outFor\n"); fflush(stdout);
if (!gotRessourceSem) {
printf("Calcul du meilleur en cas de liberation\n");
minPoolCoef= semPoolCoef[0];
idxPoolOptimum = 0;
/* on cherche le pool avec le moins de lock poses / nbre de buffer
* le numéro du pool est stocké dans idxPoolOptimum */
for(i=0; i<nbLockedSem; i++) {
printf("Coef %d : %d\n",i,semPoolCoef[i]);
if ((semPoolCoef[i] != -1)
&& (semPoolCoef[i] < minPoolCoef)) {
minPoolCoef = semPoolCoef[i];
@ -126,8 +130,10 @@ void * msgAllocate(msgSpace *space,
} else {
selectedPoolIndex=idxPoolOptimum;
}
printf("Optimum : %d\n",selectedPoolIndex);
}
}else {
fprintf(stderr,"[ ALLOCATION : %d ]\n",(int)getpid());
selectedPoolIndex=pool;
}
@ -139,13 +145,15 @@ void * msgAllocate(msgSpace *space,
NZG_ERROR("sem_open",ressourceSemId);
return NULL;
}
}
if (sem_wait(ressourceSemFd) < 0){
NZG_ERROR("sem_wait",ressourceSemId);
sem_close(ressourceSemFd);
return NULL;
}
printf("SemWait... %s\n",ressourceSemId);
if (sem_wait(ressourceSemFd) < 0){
NZG_ERROR("sem_wait",ressourceSemId);
sem_close(ressourceSemFd);
return NULL;
}
printf("Passed %s\n",ressourceSemId);
}
/* on a acqui un semaphore pour la ressouce */
/* on acquiert le droit de modifier les infos sur la ressource */
@ -164,7 +172,7 @@ void * msgAllocate(msgSpace *space,
//TODO:
/* - on s'enregistre aupres de ce buffer */
//TODO: msgBufferAttachProc(space,selectedPoolIndex,resultAddr);
sem_close(poolDataTabSemFd);

View file

@ -8,7 +8,6 @@ int bufferInfoNb;
int bufferFreeIndex;
//récuperer l'ID du BufferInfoTab;
printf("=>%s<=\n",poolDataTabAddr[poolIndex].bufferInfoTabId);
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE);

View file

@ -1,4 +1,6 @@
#include "libnazgul.h"
int msgFree(msgSpace * space, void * addr);
int msgFree(msgSpace * space, void * addr){
return -1;
}

View file

@ -9,7 +9,7 @@ int msgPoolCreate(
) {
int poolFd;
sem_t * ressourceSem;
sem_t * ressourceSemFd;
msgPoolId poolId;
msgPoolSemId poolRessourceSemId;
@ -38,9 +38,17 @@ int msgPoolCreate(
}
// on met un semaphore sur le pool
ressourceSem = sem_open(poolRessourceSemId, O_CREAT|O_EXCL, 0666, buffNb);
ressourceSemFd = sem_open(poolRessourceSemId, O_CREAT|O_EXCL, 0666, buffNb);
if (ressourceSemFd == SEM_FAILED){
NZG_ERROR("sem_open : creation de la ressource",poolRessourceSemId);
return -1;
} else {
NZG_ERROR("sem_open : creation oki",poolRessourceSemId);
}
//TODO: verrifier les erreurs sur l'ouverture de la sem
sem_close(ressourceSemFd);
// on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs

View file

@ -12,9 +12,11 @@ int msgBufferDetachProc(msgPoolData *poolDataTabAddr, int poolIndex, int bufferI
/* nzg_bufferGetFreeIndex.c */
int msgBufferGetFreeIndex(msgPoolData *poolDataTabAddr, int poolIndex);
/* nzg_bufferInfoTabCreate.c */
int msgBufferInfoTabCreate(msgSpaceId externId,msgPoolData * poolDataTabAddr, int poolIdx, int buffNb);
int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData *poolDataTabAddr, int poolIdx, int bufferNb);
/* nzg_bufferInfoTabInit.c */
int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex);
/* nzg_free.c */
int msgFree(msgSpace *space, void *addr);
/* nzg_ids.c */
int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src);
int msgPoolSemIdIntern(msgPoolSemId destSemId, const msgSpaceId srcPoolId, int poolIdx);
@ -23,7 +25,7 @@ int msgPoolIdIntern(msgPoolId dest, msgPoolId src, int num);
int msgBufferInfoTabIdIntern(msgBufferInfoTabId dest, msgSpaceId src, int num);
/* nzg_list.c */
/* nzg_msgList.c */
msgSpaceListElem *addBegining(msgSpaceListElem *list, int ownerpid);
void *add(char *idAncien, char *idNouveau);
/* nzg_poolCreate.c */
int msgPoolCreate(msgSpaceId externId, int poolIdx, int buffNb, int buffSize);
/* nzg_poolDelete.c */
@ -35,6 +37,5 @@ int msgSpaceDelete(msgSpaceId externId);
/* nzg_spaceOpen.c */
msgSpace *msgSpaceOpen(msgSpaceId spaceId);
/* nzg_state.c */
int msgFree(msgSpace * space, void * addr);
#endif

View file

@ -69,7 +69,7 @@ msgSpace * msgSpaceCreate(
return NULL;
}
printf( "msgSpace map addr is 0x%08x : %d\n", (int)mSAddr,mSFd);
printf( "CREAT: msgSpace mapped to 0x%08x in %d\n", (int)mSAddr,(int)getpid());
/* on ferme le descripteur du fichier */
close(mSFd);

View file

@ -6,11 +6,11 @@ int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
msgSpace * msgSpaceOpen(msgSpaceId externId){
int shmFd;
msgSpaceId nzgId;
msgSpace * mSAddr;
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
if (msgSpaceIdIntern(nzgId,externId) < 0){
return NULL;
}
if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
@ -19,6 +19,7 @@ msgSpace * msgSpaceOpen(msgSpaceId spaceId){
}
mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0);
printf( "OPEN: msgSpace mapped to 0x%08x in %d\n", (int)mSAddr,(int)getpid());
return mSAddr;
}