l3.libnazgul/src/queueProtLock.c

38 lines
720 B
C
Raw Normal View History

2004-02-23 18:50:52 +00:00
#include "libnazgul.h"
2004-02-23 20:00:06 +00:00
#include "ids.h"
2004-02-23 18:50:52 +00:00
#define DEBUG 0
2020-03-03 23:06:43 +00:00
int msgQueueProtLock(msgSpaceId externId, int queueIdx)
{
int semval;
sem_t *queueSemFd;
msgQueueSemId queueSemId;
2004-02-23 18:50:52 +00:00
2020-03-03 23:06:43 +00:00
msgQueueProtSemIdIntern(queueSemId, externId, queueIdx);
if (DEBUG) {
printf("Locking %s\n", queueSemId);
}
queueSemFd = sem_open(queueSemId, O_CREAT, SEM_DEFAULT_MODE, 1);
if (queueSemFd == SEM_FAILED) {
NZG_ERROR("sem_open", queueSemId);
goto ERROR;
}
2004-02-23 19:07:40 +00:00
2020-03-03 23:06:43 +00:00
if (sem_wait(queueSemFd) == -1) {
NZG_ERROR("sem_wait", queueSemId);
goto ERROR;
}
semval = 0;
sem_getvalue(queueSemFd, &semval);
if (DEBUG) {
printf("(AfterValue:%d)\n", semval);
}
2004-02-25 11:12:03 +00:00
2020-03-03 23:06:43 +00:00
sem_close(queueSemFd);
sem_close(queueSemFd);
2004-02-23 19:07:40 +00:00
2020-03-03 23:06:43 +00:00
return 0;
ERROR:
return -1;
2004-02-23 18:50:52 +00:00
}