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 * lcd_sem.c -- semaphore code written for lcdtime and meter to mediate
* access to the parallel port. * access to the parallel port.
@@ -34,7 +38,6 @@
#include "lcd_sem.h" #include "lcd_sem.h"
// according to X/OPEN we have to define it ourselves // according to X/OPEN we have to define it ourselves
//#ifdef _SEM_SEMUN_UNDEFINED
#ifndef HAVE_UNION_SEMUN #ifndef HAVE_UNION_SEMUN
union semun { union semun {
int val; /* value for SETVAL */ int val; /* value for SETVAL */
@@ -53,116 +56,125 @@ union semun {
#define SEM_WAIT 0,-1,SEM_UNDO #define SEM_WAIT 0,-1,SEM_UNDO
/* functions local to this file */ /* functions local to this file */
static key_t getkey (register char *p); static key_t getkey(register char *p);
/* global variables */ /* global variables */
static struct sembuf semaphore_wait = { SEM_WAIT }; static struct sembuf semaphore_wait = { SEM_WAIT };
static struct sembuf semaphore_signal = { SEM_SIGNAL }; static struct sembuf semaphore_signal = { SEM_SIGNAL };
/*
* getkey returns the key for the semaphore
*/
/**
* Return the key for the semaphore.
*/
static key_t 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 int
sem_get (void) sem_get(void)
{ {
int semid; int semid;
union semun semval; 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) { switch (errno) {
case EEXIST: case EEXIST:
/* semaphore set exists, get id and return it */ /* semaphore set exists, get id and return it */
if ((semid = semget (getkey (SEMAPHORE), SEMCOUNT, IPC_EXCL | WMODE)) < 0) { if ((semid = semget(getkey(SEMAPHORE), SEMCOUNT, IPC_EXCL | WMODE)) < 0) {
perror ("semget"); perror("semget");
exit (1); exit(1);
} }
return semid; return semid;
break; break;
case EACCES: case EACCES:
/* don't have permissions for semaphore, need to change key */ /* don't have permissions for semaphore, need to change key */
perror ("semget, can't get permissions for semaphore"); perror("semget, can't get permissions for semaphore");
exit (1); exit(1);
break; break;
default: default:
perror ("semget"); perror("semget");
exit (1); exit(1);
break; break;
} }
} else { } else {
/* initialise semaphore to 1 */ /* initialise semaphore to 1 */
semval.val = 1; semval.val = 1;
if (semctl (semid, 0, SETVAL, semval) < 0) { if (semctl(semid, 0, SETVAL, semval) < 0) {
perror ("setval, can't initialise semaphore"); perror("setval, can't initialise semaphore");
exit (1); exit(1);
} }
} }
return semid; 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 int
sem_wait (int sid) sem_wait(int sid)
{ {
if (semop (sid, &semaphore_wait, 1) < -1) { if (semop(sid, &semaphore_wait, 1) < -1) {
perror (SEMAPHORE); perror(SEMAPHORE);
exit (1); exit(1);
} }
return 0; 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 int
sem_signal (int sid) sem_signal(int sid)
{ {
if (semop (sid, &semaphore_signal, 1) < -1) { if (semop(sid, &semaphore_signal, 1) < -1) {
perror (SEMAPHORE); perror(SEMAPHORE);
exit (1); exit(1);
} }
return 0; 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 int
sem_remove (int sid) sem_remove(int sid)
{ {
#ifdef EIDRM #ifdef EIDRM
int i; int i;
union semun dummy; union semun dummy;
if ((i = semctl (sid, 0, IPC_RMID, dummy)) < 0) { if ((i = semctl(sid, 0, IPC_RMID, dummy)) < 0) {
switch (i) { switch (i) {
case EIDRM: case EIDRM:
/* semaphore removed */ /* semaphore removed */
return 0; return 0;
break; break;
default: default:
perror ("semctl, removing semaphore"); perror("semctl, removing semaphore");
exit (1); exit(1);
} }
} }