diff --git a/src/proto.h b/src/proto.h index ccd471d..cbd5c9f 100644 --- a/src/proto.h +++ b/src/proto.h @@ -61,14 +61,18 @@ int msgQueueElemDelete(msgQueueElemId queueElemId); void *msgQueueElemOpen(msgQueueElemId queueElemId); /* queueInit.c */ msgQueue *queueInit(msgSpaceId externId, int queueIdx); -/* queueLock.c */ -int queueLock(msgSpaceId externId, int queueIdx); /* queueOpen.c */ void *msgQueueOpen(msgQueueId queueId); +/* queueProtLock.c */ +int queueProtLock(msgSpaceId externId, int queueIdx); +/* queueProtUnlock.c */ +int queueProtUnlock(msgSpaceId externId, int queueIdx); +/* queueReadLock.c */ +int queueReadLock(msgSpaceId externId, int queueIdx); +/* queueReadUnlock.c */ +int queueReadUnlock(msgSpaceId externId, int queueIdx); /* queueRem.c */ int msgQueueElemRem(msgQueue *queue, msgQueueElemId oldElemId); -/* queueUnlock.c */ -int queueUnlock(msgSpaceId externId, int queueIdx); /* spaceCreate.c */ msgSpace *msgSpaceCreate(msgSpaceId externId, int queueNb, int poolNb, msgPool *poolInfos); /* spaceDelete.c */ diff --git a/src/queueProtLock.c b/src/queueProtLock.c index 393909f..a80405c 100644 --- a/src/queueProtLock.c +++ b/src/queueProtLock.c @@ -1,11 +1,11 @@ #include "libnazgul.h" #include "ids.h" -int queueLock(msgSpaceId externId,int queueIdx){ +int queueProtLock(msgSpaceId externId,int queueIdx){ sem_t * queueSemFd; msgQueueSemId queueSemId; - msgQueueSemIdIntern(queueSemId,externId,queueIdx); + msgQueueProtSemIdIntern(queueSemId,externId,queueIdx); queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); diff --git a/src/queueProtUnlock.c b/src/queueProtUnlock.c index 0306195..bebe704 100644 --- a/src/queueProtUnlock.c +++ b/src/queueProtUnlock.c @@ -1,11 +1,11 @@ #include "libnazgul.h" #include "ids.h" -int queueUnlock(msgSpaceId externId,int queueIdx){ +int queueProtUnlock(msgSpaceId externId,int queueIdx){ sem_t * queueSemFd; msgQueueSemId queueSemId; - msgQueueSemIdIntern(queueSemId,externId,queueIdx); + msgQueueProtSemIdIntern(queueSemId,externId,queueIdx); queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); if(queueSemFd==SEM_FAILED){ NZG_ERROR("sem_open",queueSemId); diff --git a/src/queueReadLock.c b/src/queueReadLock.c new file mode 100644 index 0000000..24a9ece --- /dev/null +++ b/src/queueReadLock.c @@ -0,0 +1,26 @@ +#include "libnazgul.h" +#include "ids.h" + +int queueReadLock(msgSpaceId externId,int queueIdx){ + sem_t * queueSemFd; + msgQueueSemId queueSemId; + + msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); + queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + if(queueSemFd==SEM_FAILED){ + NZG_ERROR("sem_open",queueSemId); + goto ERROR; + } + + if(sem_wait(queueSemFd)==-1){ + NZG_ERROR("sem_wait",queueSemId); + goto ERROR; + } + + sem_close(queueSemFd); + + return 0; +ERROR: + return -1; +} + diff --git a/src/queueReadUnlock.c b/src/queueReadUnlock.c new file mode 100644 index 0000000..cb05b02 --- /dev/null +++ b/src/queueReadUnlock.c @@ -0,0 +1,26 @@ +#include "libnazgul.h" +#include "ids.h" + +int queueReadUnlock(msgSpaceId externId,int queueIdx){ + sem_t * queueSemFd; + msgQueueSemId queueSemId; + + msgQueueReadSemIdIntern(queueSemId,externId,queueIdx); + queueSemFd=sem_open(queueSemId,O_CREAT|O_EXCL,SEM_DEFAULT_MODE,1); + if(queueSemFd==SEM_FAILED){ + NZG_ERROR("sem_open",queueSemId); + goto ERROR; + } + + if(sem_post(queueSemFd)==-1){ + NZG_ERROR("sem_post",queueSemId); + goto ERROR; + } + + sem_close(queueSemFd); + + return 0; +ERROR: + return -1; +} +