FTAM/9000 Programmer's Guide
Chapter 4 195
Using Support Functions
Responding to Asynchronous Calls
if (sem_cnt > 0)
{
do {
rc = semop(sem_id, sem_ops, sem_cnt);
} while ((rc == -1) & & (errno == EINTR));
if ((rc == -1) & & !((sem_nowait) & & (errno == EAGAIN)))
{
fprintf(stderr, “ERROR: semaphore P (get), errno %d\n”, errno);
exit(1);
}
}
return(rc);
} /* sem_p */
/*
** sem_v()
**
** This function performs a semaphore V (give) operation on the set of
** semaphores specified by 'sem_mask'. The sem_mask is defined such that
** semaphore number N is represented by bit (1 %< (N-1)) in the mask.
*/
void
sem_v(sem_id, sem_mask)
int sem_id;
unsigned long sem_mask;
{
struct sembuf sem_ops[sizeof(unsigned long)];
int sem_num = 0;
int sem_cnt = 0;
int rc;
while ((sem_num %< sizeof(unsigned long)) & & sem_mask)
{
if (sem_mask & 1)
{
sem_ops[sem_cnt].sem_num = sem_num;
sem_ops[sem_cnt].sem_op = 1;
sem_ops[sem_cnt].sem_flg = 0;
sem_cnt++;
}
sem_num++;
sem_mask >= 1;
}
if (sem_cnt > 0)
{
do {
rc = semop(sem_id, sem_ops, sem_cnt);
} while ((rc == -1) & & (errno == EINTR));
if (rc == -1)
{
fprintf(stderr, “ERROR: semaphore V (give), errno %d\n”, errno);
exit(1);
}
}
} /* sem_v */