Doxygen-ize

This commit is contained in:
marschap
2008-12-22 17:42:19 +00:00
parent 3012f2f4e0
commit 038423a10b
+55 -43
View File
@@ -1,3 +1,7 @@
/** \file server/drivers/lcd_sem.c
* semaphore code to mediate access to the parallel port.
*/
/*
* lcd_sem.c -- semaphore code written for lcdtime and meter to mediate
* access to the parallel port.
@@ -34,7 +38,6 @@
#include "lcd_sem.h"
// according to X/OPEN we have to define it ourselves
//#ifdef _SEM_SEMUN_UNDEFINED
#ifndef HAVE_UNION_SEMUN
union semun {
int val; /* value for SETVAL */
@@ -53,116 +56,125 @@ union semun {
#define SEM_WAIT 0,-1,SEM_UNDO
/* functions local to this file */
static key_t getkey (register char *p);
static key_t getkey(register char *p);
/* global variables */
static struct sembuf semaphore_wait = { SEM_WAIT };
static struct sembuf semaphore_signal = { SEM_SIGNAL };
/*
* getkey returns the key for the semaphore
*/
/**
* Return the key for the semaphore.
*/
static key_t
getkey (register char *p)
getkey(register char *p)
{
return ((key_t) SEMKEY);
return((key_t) SEMKEY);
}
/*
* create the semaphore if one doesn't exist and initialise it to 1, else
* return the semaphore set id
/**
* Get semaphore.
* If the semaphore does not exist, create it and initialise it to 1,
* otherwise simply return the semaphore ID.
* \return Semaphore ID on success; terminate program with code \c 1 on error.
*/
int
sem_get (void)
sem_get(void)
{
int semid;
union semun semval;
if ((semid = semget (getkey (SEMAPHORE), SEMCOUNT, IPC_CREAT | IPC_EXCL | WMODE)) < 0) {
if ((semid = semget(getkey(SEMAPHORE), SEMCOUNT, IPC_CREAT | IPC_EXCL | WMODE)) < 0) {
switch (errno) {
case EEXIST:
/* semaphore set exists, get id and return it */
if ((semid = semget (getkey (SEMAPHORE), SEMCOUNT, IPC_EXCL | WMODE)) < 0) {
perror ("semget");
exit (1);
if ((semid = semget(getkey(SEMAPHORE), SEMCOUNT, IPC_EXCL | WMODE)) < 0) {
perror("semget");
exit(1);
}
return semid;
break;
case EACCES:
/* don't have permissions for semaphore, need to change key */
perror ("semget, can't get permissions for semaphore");
exit (1);
perror("semget, can't get permissions for semaphore");
exit(1);
break;
default:
perror ("semget");
exit (1);
perror("semget");
exit(1);
break;
}
} else {
/* initialise semaphore to 1 */
semval.val = 1;
if (semctl (semid, 0, SETVAL, semval) < 0) {
perror ("setval, can't initialise semaphore");
exit (1);
if (semctl(semid, 0, SETVAL, semval) < 0) {
perror("setval, can't initialise semaphore");
exit(1);
}
}
return semid;
}
/*
* wait on the semaphore
*/
/**
* Wait on the semaphore.
* \param sid Semaphore ID.
* \return \c 0 on success; terminate program with code \c 1 on error.
*/
int
sem_wait (int sid)
sem_wait(int sid)
{
if (semop (sid, &semaphore_wait, 1) < -1) {
perror (SEMAPHORE);
exit (1);
if (semop(sid, &semaphore_wait, 1) < -1) {
perror(SEMAPHORE);
exit(1);
}
return 0;
}
/*
* signal on the semaphore
*/
/**
* Signal on the semaphore.
* \param sid Semaphore ID.
* \return \c 0 on success; terminate program with code \c 1 on error.
*/
int
sem_signal (int sid)
sem_signal(int sid)
{
if (semop (sid, &semaphore_signal, 1) < -1) {
perror (SEMAPHORE);
exit (1);
if (semop(sid, &semaphore_signal, 1) < -1) {
perror(SEMAPHORE);
exit(1);
}
return 0;
}
/*
* remove the semaphore
*/
/**
* Remove the semaphore
* \param sid Semaphore ID.
* \return \c 0 on success; terminate program with code \c 1 on error.
*/
int
sem_remove (int sid)
sem_remove(int sid)
{
#ifdef EIDRM
int i;
union semun dummy;
if ((i = semctl (sid, 0, IPC_RMID, dummy)) < 0) {
if ((i = semctl(sid, 0, IPC_RMID, dummy)) < 0) {
switch (i) {
case EIDRM:
/* semaphore removed */
return 0;
break;
default:
perror ("semctl, removing semaphore");
exit (1);
perror("semctl, removing semaphore");
exit(1);
}
}