From 1fac3384eebe1f993b5df35e98426c6dc88becf7 Mon Sep 17 00:00:00 2001 From: glenux Date: Sun, 22 Feb 2004 13:11:59 +0000 Subject: [PATCH] *** empty log message *** --- src/Makefile | 10 +++-- src/nzg_buffer.c | 19 ++++++++-- src/nzg_bufferAttachProc.c | 37 ++++++++++++++++++ src/nzg_bufferDetachProc.c | 36 ++++++++++++++++++ src/nzg_bufferGetFreeIndex.c | 35 ++++++++++++++++++ src/nzg_pool.c | 72 ------------------------------------ 6 files changed, 129 insertions(+), 80 deletions(-) create mode 100644 src/nzg_bufferAttachProc.c create mode 100644 src/nzg_bufferDetachProc.c create mode 100644 src/nzg_bufferGetFreeIndex.c delete mode 100644 src/nzg_pool.c diff --git a/src/Makefile b/src/Makefile index 045eca0..16dd1ed 100644 --- a/src/Makefile +++ b/src/Makefile @@ -33,8 +33,9 @@ endif all: build build : $(OFILES) - ar rc $(DESTFILE) $(OFILES) - ranlib $(DESTFILE) + @echo -e "Creating library..." + @ar rc $(DESTFILE) $(OFILES) + @ranlib $(DESTFILE) clean: @echo -e "Cleaning..." @@ -42,7 +43,8 @@ clean: @rm -f *.o %.o : %.c - $(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) $(DEFINES) -o $*.o - + @echo -e "$(CC)\t$@" + @$(CC) $(CFLAGS) -c $< $(INCLUDES) $(LIBINC) $(LIBS) $(DEFINES) -o $*.o + edit: gvim *.c *.h diff --git a/src/nzg_buffer.c b/src/nzg_buffer.c index 57a51e6..623b689 100644 --- a/src/nzg_buffer.c +++ b/src/nzg_buffer.c @@ -1,4 +1,15 @@ -/* - int msgBufferDetachProc(msgSpace * space, int poolIndex){ - } - */ +#include "libnazgul.h" + +int msgBufferGetAttachedProcIndex( + msgPoolData * poolDataTabAddr, + int poolIndex, + void * addr + ){ + + //TODO: parcourrir tous les index, et regarder s'il y + //a une addresse qui correspond avec le meme processus... + //et renvoyer l'index du buffer correspondant a l'addresse... +return 0; +} + + diff --git a/src/nzg_bufferAttachProc.c b/src/nzg_bufferAttachProc.c new file mode 100644 index 0000000..8e81bc5 --- /dev/null +++ b/src/nzg_bufferAttachProc.c @@ -0,0 +1,37 @@ +#include "libnazgul.h" + +int msgBufferAttachProc( + msgPoolData * poolDataTabAddr, + int poolIndex, + int bufferIndex, + void * addr) +{ + msgBufferInfoTabId bufferInfoTabId; + int bufferInfoTabFd; + msgBufferInfo * bufferInfoTabAddr; + int bufferInfoNb; + + //récuperer l'ID du BufferInfoTab; + strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); + if (bufferInfoTabFd<0){ + perror("shm_open"); + return -1; + } + + /** on regarde dans le tableau d'infos de buffer **/ + bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; + bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), + PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + + bufferInfoTabAddr[bufferIndex].ownerPid = getpid(); + bufferInfoTabAddr[bufferIndex].addr = addr; + + if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0) + { perror("munmap"); return -1; } + + return 0; +} + + diff --git a/src/nzg_bufferDetachProc.c b/src/nzg_bufferDetachProc.c new file mode 100644 index 0000000..24b26a4 --- /dev/null +++ b/src/nzg_bufferDetachProc.c @@ -0,0 +1,36 @@ +#include "libnazgul.h" + +int msgBufferDetachProc( + msgPoolData * poolDataTabAddr, + int poolIndex, + int bufferIndex, + void * addr + ){ + msgBufferInfoTabId bufferInfoTabId; + int bufferInfoTabFd; + msgBufferInfo * bufferInfoTabAddr; + int bufferInfoNb; + + //récuperer l'ID du BufferInfoTab; + strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); + if (bufferInfoTabFd<0){ + perror("shm_open"); + return -1; + } + + /** on regarde dans le tableau d'infos de buffer **/ + bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; + bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), + PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + + bufferInfoTabAddr[bufferIndex].ownerPid = (pid_t)-1; + bufferInfoTabAddr[bufferIndex].addr = NULL; + + if (munmap(bufferInfoTabAddr,bufferInfoNb*sizeof(msgBufferInfo))< 0) + { perror("munmap"); return -1; } + + return 0; +} + diff --git a/src/nzg_bufferGetFreeIndex.c b/src/nzg_bufferGetFreeIndex.c new file mode 100644 index 0000000..4a0f9d3 --- /dev/null +++ b/src/nzg_bufferGetFreeIndex.c @@ -0,0 +1,35 @@ +#include "libnazgul.h" + +int msgBufferGetFreeIndex(msgPoolData * poolDataTabAddr,int poolIndex){ + msgBufferInfoTabId bufferInfoTabId; +int bufferInfoTabFd; +msgBufferInfo * bufferInfoTabAddr; +int bufferInfoNb; +int bufferFreeIndex; + + //récuperer l'ID du BufferInfoTab; + strcpy(bufferInfoTabId, poolDataTabAddr[poolIndex].bufferInfoTabId); + + bufferInfoTabFd=shm_open(bufferInfoTabId,O_RDWR,SHM_DEFAULT_MODE); + if (bufferInfoTabFd<0){ + perror("shm_open"); + return -1; + } + + /** on regarde dans le tableau d'infos de buffer **/ + bufferInfoNb=poolDataTabAddr[poolIndex].bufferNb; + bufferInfoTabAddr=mmap(NULL,bufferInfoNb*sizeof(msgBufferInfo), + PROT_READ,MAP_SHARED,bufferInfoTabFd,(off_t)0); + + int i=0; + while ((i