* renommages

This commit is contained in:
glenux 2004-02-22 11:50:29 +00:00
parent b6f07d0e1e
commit 634e65599b
7 changed files with 88 additions and 82 deletions

View file

@ -29,11 +29,14 @@ void * msgAllocate(msgSpace *space,
int * ressourceSemVal=NULL;
float minPoolCoef;
int selectedPoolIndex;
int bufferFreeIndex;
selectedPoolIndex=-1;
/* TODO: verifier le premier arg du shm_open */
mSPoolDataTabFd=shm_open(space->poolDataTabId,O_RDWR,MSGSPACE_DEFAULT_MODE);
mSPoolDataTabFd=shm_open(space->poolDataTabId,
O_RDWR,
MSGSPACE_DEFAULT_MODE);
if (mSPoolDataTabFd == -1 ) {
fprintf( stderr, "Allocate %s failed: %s\n",
(char*)space->poolDataTabId,
@ -41,13 +44,13 @@ void * msgAllocate(msgSpace *space,
return NULL;
}
msgPoolData * mSPoolDataTab;
msgPoolData * mSPoolDataTabAddr;
mSPoolDataTab = mmap( 0, (space->poolNb) * sizeof( msgPoolData ),
mSPoolDataTabAddr = mmap( 0, (space->poolNb) * sizeof( msgPoolData ),
PROT_READ | PROT_WRITE,
MAP_SHARED, mSPoolDataTabFd, 0 );
if( mSPoolDataTab == MAP_FAILED) {
if( mSPoolDataTabAddr == MAP_FAILED) {
fprintf( stderr, "mmap failed: %s\n",
strerror( errno ) );
return NULL;
@ -64,26 +67,24 @@ void * msgAllocate(msgSpace *space,
if ( pool == ANYPOOL){
// choisir le pool au hasard (ou presque)
for(i=0; i<(space->poolNb); i++) {
if(mSPoolDataTab[i].bufferSize >= taille) {
if(mSPoolDataTabAddr[i].bufferSize >= taille) {
/* choisir le numero du semaphore
en fonction du nombre de lock poses / nombre de buffer */
msgPoolSemIdIntern(ressourceSemId,space->id,i);
ressourceSemFd = sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
if (ressourceSemFd == SEM_FAILED){
#warning "Gérer mieu les erreurs..."
perror("sem_open"); return NULL;
}
/* on remplit le tableau avec les valeurs des semaphores */
if (sem_getvalue(ressourceSemFd, ressourceSemVal) < 0){
#warning "Gérer mieu les erreurs..."
perror("sem_getvalue"); return NULL;
}
if ((*ressourceSemVal) < 0){
/* il y a ressourceSemVal processus qui attendent déja... */
semPoolCoef[nbLockedSem] =
(float) (- (*ressourceSemVal) / mSPoolDataTab[i].bufferNb);
(float) (- (*ressourceSemVal) / mSPoolDataTabAddr[i].bufferNb);
nbLockedSem++;
}
if(sem_trywait(ressourceSemFd)) {
@ -94,7 +95,6 @@ void * msgAllocate(msgSpace *space,
break;
}
if( sem_close(ressourceSemFd) <0){
#warning "Gérer mieu les erreurs..."
perror("sem_getvalue"); return NULL;
}
} // if buffSize > taille
@ -125,7 +125,7 @@ void * msgAllocate(msgSpace *space,
}
if (!gotRessourceSem){
strcpy(resultPoolId,mSPoolDataTab[selectedPoolIndex].id);
strcpy(resultPoolId,mSPoolDataTabAddr[selectedPoolIndex].id);
msgPoolSemIdIntern(ressourceSemId,space->id,selectedPoolIndex);
ressourceSemFd=sem_open(ressourceSemId,O_CREAT,SEM_DEFAULT_MODE,0);
if(ressourceSemFd==SEM_FAILED){
@ -146,8 +146,13 @@ void * msgAllocate(msgSpace *space,
/* on modifie maintenant les données */
/* - on récupere l'index du premier buffer libre */
//TODO:int bufferFreeIndex = msgBufferGetFreeIndex(space,selectedPoolIndex);
bufferFreeIndex = msgBufferGetFreeIndex(mSPoolDataTabAddr,selectedPoolIndex);
if (bufferFreeIndex < 0){
sem_close(poolDataTabSemFd);
// aucun buffer libre ?
return NULL;
}
printf("Buffer %d libre a attacher !\n",bufferFreeIndex);
/*TODO: mapper le buffer libre dans l'esp addr du proc */
//TODO:
/* - on s'enregistre aupres de ce buffer */

View file

@ -1,10 +1,4 @@
#include "libnazgul.h"
#include "nzg_ids.h"
int msgBufferGetFreeIndex(msgSpaceId spaceId,int poolIndex){
return -1;
}
int msgBufferAttachProc(msgSpaceId spaceId,int poolIndex,void * addr){
return -1;
}
/*
int msgBufferDetachProc(msgSpace * space, int poolIndex){
}
*/

View file

@ -5,7 +5,6 @@ int msgBufferInit(msgPoolData * poolDataTabAddr,int poolIndex){
int bufferInfoTabFd;
msgBufferInfo * bufferInfoTabAddr;
int bufferInfoNb;
int bufferFreeIndex;
//récuperer l'ID du BufferInfoTab;
strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId);
@ -21,16 +20,14 @@ int bufferFreeIndex;
bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo),
PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0);
int i=0;
while ((i<bufferInfoNb)
&& (bufferInfoTabAddr[i].ownerPid != (pid_t)-1)){ i++; }
if (i == bufferInfoNb){ return -1; }
bufferFreeIndex=i;
int i;
for (i=0;i<bufferInfoNb;i++){
bufferInfoTabAddr[i].ownerPid = (pid_t)-1;
}
if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0)
{ perror("munmap"); return -1; }
return -1;
return 0;
}

View file

@ -14,7 +14,7 @@ msgSpace *msgSpaceOpen(msgSpaceId spaceId);
int msgSpaceDelete(msgSpaceId spaceId);
/* src/nzg_buffer.c */
int msgBufferGetFreeIndex(msgPoolData * poolDataTab, int poolIndex);
int msgBufferAttachProc(msgPoolData * poolDataTab, int poolIndex, void *addr);
int msgBufferAttachProc(msgPoolData * poolDataTab, int poolIndex, int bufferIndex,void *addr);
#endif

View file

@ -1,10 +1,7 @@
#include "libnazgul.h"
#include "nzg_ids.h"
/* prototypes des f#define MSGSPACE_DEFAULT_MODE 0600
#define MSGSPACE_ID_LEN 32
onctions annexes à ne pas exporter */
/* prototypes des fonctions annexes à ne pas exporter */
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
@ -146,51 +143,4 @@ msgSpace * msgSpaceCreate(
}
/*
* spaceId : blabla
*/
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmFd;
msgSpaceId nzgId;
msgSpace * mSAddr;
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
}
mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0);
return mSAddr;
}
int msgSpaceDelete(msgSpaceId spaceId){
fprintf(stderr,"Deleting msgSpace with id : %s\n",spaceId);
//int shmId;
msgSpaceId nzgId;
msgSpace * space;
if (msgSpaceIdIntern(nzgId,spaceId) == -1){
//TODO: message d'erreur
return -1;
}
space = msgSpaceOpen(spaceId);
/* TODO: supprimer chaque pool */
printf("openned successfully !\n");
printf("Unlinking DataTab... ");
if (shm_unlink(space->poolDataTabId) < 0){
perror("shm_unlink");
return -1;
}
printf("ok\n");
if (shm_unlink(nzgId)<0){
perror("shm_unlink");
return -1;
};
return 0;
}

35
src/nzg_spaceDelete.c Normal file
View file

@ -0,0 +1,35 @@
#include "libnazgul.h"
#include "nzg_ids.h"
/* prototypes des fonctions annexes à ne pas exporter */
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgSpaceDelete(msgSpaceId spaceId){
fprintf(stderr,"Deleting msgSpace with id : %s\n",spaceId);
//int shmId;
msgSpaceId nzgId;
msgSpace * space;
if (msgSpaceIdIntern(nzgId,spaceId) == -1){
//TODO: message d'erreur
return -1;
}
space = msgSpaceOpen(spaceId);
/* TODO: supprimer chaque pool */
printf("openned successfully !\n");
printf("Unlinking DataTab... ");
if (shm_unlink(space->poolDataTabId) < 0){
perror("shm_unlink");
return -1;
}
printf("ok\n");
if (shm_unlink(nzgId)<0){
perror("shm_unlink");
return -1;
};
return 0;
}

25
src/nzg_spaceOpen.c Normal file
View file

@ -0,0 +1,25 @@
#include "libnazgul.h"
#include "nzg_ids.h"
/* prototypes des fonctions annexes à ne pas exporter */
int msgSpaceIdIntern(msgSpaceId dest,const msgSpaceId src );
int msgPoolDataIdIntern(msgSpaceId dest,const msgSpaceId src );
msgSpace * msgSpaceOpen(msgSpaceId spaceId){
int shmFd;
msgSpaceId nzgId;
msgSpace * mSAddr;
if (msgSpaceIdIntern(nzgId,spaceId) < 0){
return NULL;
}
if ((shmFd=shm_open(nzgId,O_RDWR,MSGSPACE_DEFAULT_MODE)) < 0){
perror("shm_open");
return NULL;
}
mSAddr=mmap(NULL,sizeof(msgSpace),PROT_READ|PROT_WRITE,MAP_SHARED,shmFd,(off_t)0);
return mSAddr;
}