l3.libnazgul/src/nzg_pool.c
2020-03-03 23:46:32 +01:00

53 lines
1.1 KiB
C

#include "libnazgul.h"
#include "nzg_ids.h"
/* pid[]
liste process demandeurs */
int msgPoolCreate(
msgSpaceId spaceId,
int poolIdx,
int buffNb,
int buffSize
) {
int poolFd;
static int poolNb;
sem_t * sem;
msgPoolId poolId;
msgPoolSemId poolSemId;
if (msgPoolIdIntern(poolId,spaceId,poolIdx) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n",
(char*)poolId );
return -1;
}
poolFd=shm_open(poolId,O_RDWR|O_CREAT|O_EXCL|O_TRUNC,MSGSPACE_DEFAULT_MODE);
if (poolFd == -1 ) {
fprintf( stderr, "msgPool : %s creation failed: %s\n",poolId,
strerror( errno ) );
return -1;
}
if (msgPoolSemIdIntern(poolSemId,spaceId,poolIdx) == -1){
fprintf( stderr, "msgPoolId creation failed for id %s\n",
(char*)poolSemId );
return -1;
}
// on met un semaphore sur le pool
sem = sem_open(poolSemId, O_CREAT|O_EXCL, 0666, buffNb);
// on met le pool a la taille voulue pour qu'il
// puisse contenir les buffs
if (ftruncate(poolFd, (buffSize*buffNb)) == -1){
fprintf( stderr, "msgPool resizing failed: %s\n",
strerror( errno ) );
return -1;
}
close(poolFd);
return 0;
}