l3.libnazgul/src/queueReadTryLock.c

34 lines
655 B
C
Raw Normal View History

2004-02-24 11:01:18 +00:00
#include "libnazgul.h"
#include "ids.h"
int msgQueueReadTryLock(msgSpaceId externId,int queueIdx){
sem_t * queueSemFd;
msgQueueSemId queueSemId;
msgQueueReadSemIdIntern(queueSemId,externId,queueIdx);
2004-02-25 11:12:03 +00:00
queueSemFd=sem_open(queueSemId,O_CREAT,SEM_DEFAULT_MODE,1);
2004-02-24 11:01:18 +00:00
if(queueSemFd==SEM_FAILED){
NZG_ERROR("sem_open",queueSemId);
goto ERROR;
}
if(sem_trywait(queueSemFd)==-1){
NZG_ERROR("sem_wait",queueSemId);
goto ERROR;
}
2004-02-25 11:12:03 +00:00
printf("Locking %s\n",queueSemId);
int semval=0;
sem_getvalue(queueSemFd,&semval);
printf("(AfterValue:%d)\n",semval);
sem_close(queueSemFd);
2004-02-24 11:01:18 +00:00
sem_close(queueSemFd);
return 0;
ERROR:
return -1;
}