diff --git a/src/get.c b/src/get.c index e69de29..6ced0a5 100644 --- a/src/get.c +++ b/src/get.c @@ -0,0 +1,29 @@ +#include "libnazgul.h" + +#define NONBLOCK -1 + +void * msgGet(msgSpace * space,int queueIndex,int option){ + void * resultAddr; + // on teste la possibilité de lecture sur la liste... + if (option == NONBLOCK){ + if (msgQueueReadTryLock(space->externId,queueIndex) <0){ + NZG_ERROR("msgQueueReadTryLock",space->externId); + goto ERROR; + } + } else { + if (msgQueueReadLock(space->externId,queueIndex) <0){ + NZG_ERROR("msgQueueReadLock",space->externId); + goto ERROR; + } + } + // la lecture est possible + // on essaye donc de modifier la liste + msgQueueProtLock(space->externId,queueIndex); + + // on a fini de modifier la liste + msgQueueProtUnlock(space->externId,queueIndex); + + return resultAddr; +ERROR: + return NULL; +} diff --git a/src/proto.h b/src/proto.h index aebea80..417f466 100644 --- a/src/proto.h +++ b/src/proto.h @@ -19,6 +19,8 @@ int msgBufferInfoTabCreate(msgSpaceId externId, msgPoolData *poolDataTabAddr, in int msgBufferInfoTabInit(msgPoolData *poolDataTabAddr, int poolIndex); /* free.c */ int msgFree(msgSpace *space, void *addr); +/* get.c */ +void *msgGet(msgSpace *space, int queueIndex, int option); /* ids.c */ int msgSpaceIdIntern(msgSpaceId dest, const msgSpaceId src); int msgPoolDataTabSemIdIntern(msgPoolSemId destSemId, const msgSpaceId externId); @@ -70,6 +72,8 @@ int msgQueueProtLock(msgSpaceId externId, int queueIdx); int msgQueueProtUnlock(msgSpaceId externId, int queueIdx); /* queueReadLock.c */ int msgQueueReadLock(msgSpaceId externId, int queueIdx); +/* queueReadTryLock.c */ +int msgQueueReadTryLock(msgSpaceId externId, int queueIdx); /* queueReadUnlock.c */ int msgQueueReadUnlock(msgSpaceId externId, int queueIdx); /* queueRem.c */