This commit is contained in:
stormrider1982 2004-02-19 23:30:05 +00:00 committed by Glenn Y. Rolland
parent a776db4025
commit 179668953a
3 changed files with 105 additions and 89 deletions

View file

@ -9,6 +9,7 @@
#include <sys/types.h>
#include <sys/mman.h> /* shm_open */
#include <errno.h>
#include <semaphore.h>
#define PAGESIZE sysconf(_SC_PAGESIZE)
#define MSGSPACE_DEFAULT_MODE 0600

View file

@ -25,7 +25,7 @@ int test(int argc,char **argv){
ma_liste=addBegining(ma_liste, 5);
for (listMove=ma_liste ;listMove!=NULL ; listMove=listMove->next)
{
printf("valaeur :%d\n",listMove->ownerpid);
printf("valaeur :%d\n",listMove->ownerPid);
}
return(0);
}

View file

@ -57,29 +57,44 @@ int msgSpacePoolId2nzgPoolId(msgSpacePoolId dest,msgSpacePoolId src, int num){
msgPool * msgPoolAllocate(int poolIdx, msgSpace *msg) {
msgPool * poolAddr;
int dataId;
//msgSpacePoolDataId dataId;
msgPoolData * poolData;
int i, buffSize, poolId;
sem_t * sem;
poolId = -1;
// TODO:récupérer l'id du poolData dans le msgSpace
// détacher le morceau de mémoire du processus
//dataId = msg->poolDataId;
// TODO:récupérer le poolData qui correspond à notre poolIdx.
// attacher la zone mémoire correspondant à l'Id
// utiliser des sémaphores pour vérouiller les acces en modif
// sur la poolData de notre
//msgSpacePoolData spoolData;
//dataId = msg->poolDataId;
//spoolData[dataId];
buffSize = poolData[poolIdx].bufferSize;
if(poolData[poolIdx].allocOverload == 1) {
for(i=0; i<128; i++) {
if( (poolData[i].allocOverload != 1)
&& (poolData[i].bufferSize >= buffSize) ) {
buffSize = poolData[i].bufferSize;
poolId = i;
}
}
}
//donne l'adr en mappant in the memory
//GYR:poolAddr = mmap(NULL, sizeof(*msgPool), PROT_NONE, MAP_SHARED, poolFd, 0);
if(poolAddr == MAP_FAILED) {
fprintf( stderr, "mmap failed: %s\n",
strerror( errno ) );
fprintf( stderr, "mmap failed: %s\n", strerror( errno ) );
return NULL;
}
// semaphores
sem = sem_open(poolData[(poolId != -1)?poolId:poolIdx].id, O_CREAT|O_EXCL, 0);
sem_wait(sem);
// on renvoie le pointeur sur le bon pool
return poolAddr;