l3.libnazgul/src/spaceListLocking.c

66 lines
1.4 KiB
C

#include "libnazgul.h"
// verouille le semaphore de la liste
int msgSpaceListLock()
{
sem_t *msgSpaceListSemFd;
msgSpaceListSemId spaceListSemId;
strcpy(spaceListSemId, DEFAULT_MSGSPACELISTSEMID);
/* Ouverture d'un semafore */
msgSpaceListSemFd = sem_open(spaceListSemId, O_CREAT, 0666, 1);
if (msgSpaceListSemFd == SEM_FAILED) {
NZG_ERROR("sem_open", spaceListSemId);
goto ERROR;
}
/* Pose d'un semaphore et le verrouille */
if (sem_wait(msgSpaceListSemFd) == -1) {
NZG_ERROR("sem_wait", spaceListSemId);
goto ERROR;
}
/* Ferme le semaphore */
/* if(sem_close(msgSpaceListSemFd)==-1){
NZG_ERROR("sem_close",spaceListSemId);
return -1;
} */
sem_close(msgSpaceListSemFd);
return 0;
ERROR:
return -1;
}
// deverouille le semaphore de la liste
int msgSpaceListUnlock()
{
sem_t *msgSpaceListSemFd;
msgSpaceListSemId spaceListSemId;
strcpy(spaceListSemId, DEFAULT_MSGSPACELISTSEMID);
/*Ouverture dun semaphore */
msgSpaceListSemFd = sem_open(spaceListSemId, O_CREAT, 0666, 0);
if (msgSpaceListSemFd == SEM_FAILED) {
NZG_ERROR("sem_open", spaceListSemId);
goto ERROR;
}
/*Relachement du semaphore */
if (sem_post(msgSpaceListSemFd) == -1) {
NZG_ERROR("sem_relache", spaceListSemId);
goto ERROR;
}
/* Ferme le semaphore */
if (sem_close(msgSpaceListSemFd) == -1) {
NZG_ERROR("sem_close", spaceListSemId);
goto ERROR;
}
return 0;
ERROR:
return -1;
};