ac8072290f
* verrouillé le semaphore dans create
59 lines
1.5 KiB
C
59 lines
1.5 KiB
C
#include "libnazgul.h"
|
|
#include "nzg_ids.h"
|
|
|
|
int msgPoolCreate(
|
|
msgSpaceId externId,
|
|
int poolIdx,
|
|
int buffNb,
|
|
int buffSize
|
|
) {
|
|
|
|
int poolFd;
|
|
sem_t * ressourceSemFd;
|
|
msgPoolId poolId;
|
|
msgPoolSemId poolRessourceSemId;
|
|
|
|
/* creation des buffers DEBUT */
|
|
if (msgPoolIdIntern(poolId,externId,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 (ftruncate(poolFd, (buffSize*buffNb)) == -1){
|
|
fprintf( stderr, "msgPool resizing failed: %s\n",
|
|
strerror( errno ) );
|
|
return -1;
|
|
}
|
|
/* creation des buffers FIN */
|
|
|
|
if (msgPoolSemIdIntern(poolRessourceSemId,externId,poolIdx) == -1){
|
|
fprintf( stderr, "msgPoolId creation failed for id %s\n",
|
|
(char*)poolRessourceSemId );
|
|
return -1;
|
|
}
|
|
|
|
// on met un semaphore sur le pool
|
|
ressourceSemFd = sem_open(poolRessourceSemId, O_CREAT|O_EXCL,SEM_DEFAULT_MODE, 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
|
|
|
|
close(poolFd);
|
|
|
|
return 0;
|
|
}
|
|
|