Fix issues related to internal/external ID

This commit is contained in:
Glenn Y. Rolland 2019-09-17 14:47:35 +02:00
parent 6919f5aa12
commit 2662df9632
7 changed files with 51 additions and 32 deletions

View file

@ -55,7 +55,7 @@ void * msgAllocate(msgSpace *space,
return NULL;
}
gotRessourceSem=false;
gotRessourceSem=false;
/* initialisation des coefs */
for (i=0;i<(space->poolNb);i++){
@ -64,7 +64,7 @@ void * msgAllocate(msgSpace *space,
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);
@ -81,38 +81,42 @@ void * msgAllocate(msgSpace *space,
/* on remplit le tableau avec les valeurs des semaphores */
if (sem_getvalue(ressourceSemFd, &ressourceSemVal) < 0){
NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL;
NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL;
}
if ((ressourceSemVal) < 0){
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,12 +145,14 @@ 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 */

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;
}