FTAM/9000 Programmer's Guide

Chapter 4 193
Using Support Functions
Responding to Asynchronous Calls
/*
** Determine the event type based on the signal received.
** Update the semaphore mask to include the event type specific
** semaphore.
*/
if (sig == SIG_MAP)
sem_mask |= SEM_MAP;
else if (sig == SIG_NON_MAP)
sem_mask |= SEM_NON_MAP;
else {
fprintf(stderr, “ERROR: unsupported signal, %d\n”, sig);
exit(1);
}
/*
** Perform a V (give) operation on the specified semaphores so that the
** process can resume (if suspended), and the event count for the given
** type is incremented atomically.
*/
sem_v(sem_id, sem_mask);
} /* signal_handler */
/*
** sem_create()
**
** This function creates a semaphore array for the specified number of
** semaphores (up to 32) and initializes them to an “unblocked” state.
*/
int
sem_create(sem_cnt)
int sem_cnt;
{
int sem_id;
ushort sem_val[sizeof(unsigned long)];
sem_id = semget(IPC_PRIVATE, sem_cnt, IPC_CREAT | 0600);
if (sem_id == -1)
{
fprintf(stderr, “ERROR: creating semaphore, errno %d\n”, errno);
exit(1);
}
memset(sem_val, 0, sizeof(sem_val));
if (semctl(sem_id, 0, SETALL, sem_val) == -1)
{
fprintf(stderr, “ERROR: initializing semaphore, errno %d\n”, errno);
exit(1);
}
return(sem_id);
}