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; return NULL;
} }
gotRessourceSem=false; gotRessourceSem=false;
/* initialisation des coefs */ /* initialisation des coefs */
for (i=0;i<(space->poolNb);i++){ for (i=0;i<(space->poolNb);i++){
@ -64,7 +64,7 @@ void * msgAllocate(msgSpace *space,
int nbLockedSem=0; int nbLockedSem=0;
if ( pool == ANYPOOL){ if ( pool == ANYPOOL){
fprintf(stderr,">>>> ANYPOOL selection <<<<\n"); fprintf(stderr,"[ ALLOCATION ANYPOOL : %d ]\n",(int)getpid());
// choisir le pool au hasard (ou presque) // choisir le pool au hasard (ou presque)
for(i=0; i<(space->poolNb); i++) { for(i=0; i<(space->poolNb); i++) {
printf("ERRORDETECT boucle %d\n",i); fflush(stdout); 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 */ /* 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); NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL; return NULL;
} }
printf("RESSOURCESEMVAL %d\n",ressourceSemVal);
if ((ressourceSemVal) < 0){ if (ressourceSemVal <= 0){
printf("resVal < 0 : %d\n",ressourceSemVal);
/* il y a ressourceSemVal processus qui attendent déja... */ /* il y a ressourceSemVal processus qui attendent déja... */
semPoolCoef[nbLockedSem] = semPoolCoef[nbLockedSem] =
(float) (- (ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb); (float) (- (ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb);
nbLockedSem++; nbLockedSem++;
} }
if(sem_trywait(ressourceSemFd)==0) { if(sem_trywait(ressourceSemFd)==0) {
printf("got try_wait\n");
/* choisir la 1ere pool de taille plus grande /* choisir la 1ere pool de taille plus grande
* libre si possible */ * libre si possible */
gotRessourceSem=true; gotRessourceSem=true;
selectedPoolIndex=i; selectedPoolIndex=i;
break; break;
} }
if( sem_close(ressourceSemFd) <0){ if( sem_close(ressourceSemFd) <0){
NZG_ERROR("sem_getvalue",ressourceSemId); NZG_ERROR("sem_getvalue",ressourceSemId);
return NULL; return NULL;
} }
} // if buffSize > taille } // if buffSize > taille
} // for } // for
printf("ERRORDETECT\n"); fflush(stdout); printf("ERRORDETECT outFor\n"); fflush(stdout);
if (!gotRessourceSem) { if (!gotRessourceSem) {
printf("Calcul du meilleur en cas de liberation\n");
minPoolCoef= semPoolCoef[0]; minPoolCoef= semPoolCoef[0];
idxPoolOptimum = 0; idxPoolOptimum = 0;
/* on cherche le pool avec le moins de lock poses / nbre de buffer /* on cherche le pool avec le moins de lock poses / nbre de buffer
* le numéro du pool est stocké dans idxPoolOptimum */ * le numéro du pool est stocké dans idxPoolOptimum */
for(i=0; i<nbLockedSem; i++) { for(i=0; i<nbLockedSem; i++) {
printf("Coef %d : %d\n",i,semPoolCoef[i]);
if ((semPoolCoef[i] != -1) if ((semPoolCoef[i] != -1)
&& (semPoolCoef[i] < minPoolCoef)) { && (semPoolCoef[i] < minPoolCoef)) {
minPoolCoef = semPoolCoef[i]; minPoolCoef = semPoolCoef[i];
@ -126,8 +130,10 @@ void * msgAllocate(msgSpace *space,
} else { } else {
selectedPoolIndex=idxPoolOptimum; selectedPoolIndex=idxPoolOptimum;
} }
printf("Optimum : %d\n",selectedPoolIndex);
} }
}else { }else {
fprintf(stderr,"[ ALLOCATION : %d ]\n",(int)getpid());
selectedPoolIndex=pool; selectedPoolIndex=pool;
} }
@ -139,12 +145,14 @@ void * msgAllocate(msgSpace *space,
NZG_ERROR("sem_open",ressourceSemId); NZG_ERROR("sem_open",ressourceSemId);
return NULL; return NULL;
} }
}
if (sem_wait(ressourceSemFd) < 0){ printf("SemWait... %s\n",ressourceSemId);
NZG_ERROR("sem_wait",ressourceSemId); if (sem_wait(ressourceSemFd) < 0){
sem_close(ressourceSemFd); NZG_ERROR("sem_wait",ressourceSemId);
return NULL; sem_close(ressourceSemFd);
return NULL;
}
printf("Passed %s\n",ressourceSemId);
} }
/* on a acqui un semaphore pour la ressouce */ /* on a acqui un semaphore pour la ressouce */

View file

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

View file

@ -1,4 +1,6 @@
#include "libnazgul.h" #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; int poolFd;
sem_t * ressourceSem; sem_t * ressourceSemFd;
msgPoolId poolId; msgPoolId poolId;
msgPoolSemId poolRessourceSemId; msgPoolSemId poolRessourceSemId;
@ -38,9 +38,17 @@ int msgPoolCreate(
} }
// on met un semaphore sur le pool // 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 //TODO: verrifier les erreurs sur l'ouverture de la sem
sem_close(ressourceSemFd);
// on met le pool a la taille voulue pour qu'il // on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs // puisse contenir les buffs

View file

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

View file

@ -69,7 +69,7 @@ msgSpace * msgSpaceCreate(
return NULL; 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 */ /* on ferme le descripteur du fichier */
close(mSFd); close(mSFd);

View file

@ -6,11 +6,11 @@ int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src ); int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
msgSpace * msgSpaceOpen(msgSpaceId spaceId){ msgSpace * msgSpaceOpen(msgSpaceId externId){
int shmFd; int shmFd;
msgSpaceId nzgId; msgSpaceId nzgId;
msgSpace * mSAddr; msgSpace * mSAddr;
if (msgSpaceIdIntern(nzgId,spaceId) < 0){ if (msgSpaceIdIntern(nzgId,externId) < 0){
return NULL; return NULL;
} }
if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){ 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); 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; return mSAddr;
} }