38 lines
703 B
C
38 lines
703 B
C
#include "libnazgul.h"
|
|
#include "ids.h"
|
|
|
|
#define DEBUG 0
|
|
|
|
int msgQueueReadTryLock(msgSpaceId externId, int queueIdx)
|
|
{
|
|
int semval;
|
|
sem_t *queueSemFd;
|
|
msgQueueSemId queueSemId;
|
|
|
|
msgQueueReadSemIdIntern(queueSemId, externId, queueIdx);
|
|
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
|
|
if (queueSemFd == SEM_FAILED) {
|
|
NZG_ERROR("sem_open", queueSemId);
|
|
goto ERROR;
|
|
}
|
|
|
|
if (sem_trywait(queueSemFd) == -1) {
|
|
NZG_ERROR("sem_wait", queueSemId);
|
|
goto ERROR;
|
|
}
|
|
if (DEBUG) {
|
|
printf("Locking %s\n", queueSemId);
|
|
}
|
|
semval = 0;
|
|
sem_getvalue(queueSemFd, &semval);
|
|
if (DEBUG) {
|
|
printf("(AfterValue:%d)\n", semval);
|
|
}
|
|
|
|
sem_close(queueSemFd);
|
|
|
|
return 0;
|
|
ERROR:
|
|
return -1;
|
|
}
|