From 6272f135ed4a2633c2fb87466adf2f5f85c8c7a7 Mon Sep 17 00:00:00 2001 From: rivka_zan Date: Sun, 22 Feb 2004 18:43:20 +0000 Subject: [PATCH] *fonction msgListLock --- src/nzg_msgList.c | 97 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 25 deletions(-) diff --git a/src/nzg_msgList.c b/src/nzg_msgList.c index 4820c85..1946612 100644 --- a/src/nzg_msgList.c +++ b/src/nzg_msgList.c @@ -29,39 +29,86 @@ int msgSpaceListElemLinkNext(msgSpaceListElemId current,msgSpaceListElemId next) int msgSpaceListAdd(msgSpaceListElemId ); int msgSpaceListRem(msgSpaceListElemId spaceId); +char *spaceList; -void *add(char * idAncien, char *idNouveau); -int descMemory; +int msgSpaceListLock(){ + char *spaceList; + /*Pose d'un semafore*/ + sem_t * sem; -void * add(char * idAncien, char *idNouveau){ - descMemory=shm_open("/titi", - O_RDWR|O_CREAT|O_EXCL|O_TRUNC, - 0600); - - if (descMemory== -1){ - printf("erreur de sh_open\n"); - return NULL; - }; - - if (ftruncate(descMemory,1024)== -1 ){ - printf("erreur ftruncate"); + if((int)sem=sem_open(spaceList,O_CREAT|O_EXCL, 0666,10) ==-1){ + printf("erreur de semaphore"); + return -1; } - /* memory= mmap(0, 1024, - PROT_READ | PROT_WRITE, - - MAP_SHARED, mSFd, 0)*/ - - /* if( Strcpy(idAncien, idNouveau) ==-1){ - printf("erreur de strcpy"); - };*/ - - strcpy(idAncien, idNouveau); - return NULL; + if(sem_wait(sem)==-1){ + printf("erreur pour l'ajout d'un semaphore"); + return -1; + } + return 0; } +/*int msgSpaceListUnlock(){ + Ferme le semaphore + int semClose; + if(semClose=sem_close(spaceList) )==-1{ + printf("erreur"); + return -1; + } + + + return 0; +}; +*/ + + + + + + + + +/*void *add(char * idAncien, char *idNouveau); + int descMemory; + + void * add(char * idAncien, char *idNouveau){ + descMemory=shm_open("/titi", + O_RDWR|O_CREAT|O_EXCL|O_TRUNC, + 0600); + + if (descMemory== -1){ + printf("erreur de sh_open\n"); + return NULL; + }; + + if (ftruncate(descMemory,1024)== -1 ){ + printf("erreur ftruncate"); + } + + memory= mmap(0, 1024, + PROT_READ | PROT_WRITE, + + + MAP_SHARED, mSFd, 0)*/ +/*typedef struct MsgSpaceListElem { + void * id; + int ownerPid; + msgSpaceListElemId next; + } * msgSpaceList, msgSpaceListElem; + + msgSpaceListElemId *mslist; + + if( Strcpy(idAncien, idNouveau) ==-1){ + printf("erreur de strcpy"); + }; + + strcpy(idAncien, idNouveau); + return NULL; + + } + */