Main Page | Modules | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

semaphores.c

Go to the documentation of this file.
00001 
00011 /* {{{ Initial comments */
00012 /*
00013  * $LastChangedDate: 2003-11-27 01:55:17 +0100 (Thu, 27 Nov 2003) $
00014  * $LastChangedRevision: 5 $
00015  * $LastChangedBy: ckruse $
00016  *
00017  */
00018 /* }}} */
00019 
00020 /* {{{ Includes */
00021 #include "config.h"
00022 #include "defines.h"
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 #include <sys/types.h>
00029 
00030 #include <sys/ipc.h>
00031 #include <sys/shm.h>
00032 #include <sys/sem.h>
00033 
00034 #include <unistd.h>
00035 #include <errno.h>
00036 
00037 #include "semaphores.h"
00038 /* }}} */
00039 
00040 /*
00041  * Generally, this function does a semop()-operation to a specified semaphore in a set.
00042  * The SEM_UNDO flag will be set. Operation can either be greater 0, smaller 0 and equal 0. Greater
00043  * 0 means, increase the value of a semaphore by the specified value, < 0 means, decrease the semaphore
00044  * value by this specified value and equal 0 means, wait until the semaphore is 0.
00045  */
00046 int cf_sem_pv(int id,int operation,int semnum) {
00047   struct sembuf semaphor;
00048   semaphor.sem_op   = operation;
00049   semaphor.sem_flg  = SEM_UNDO;
00050   semaphor.sem_num  = semnum;
00051 
00052   return semop(id,&semaphor,1);
00053 }
00054 
00055 int cf_sem_getval(int id,int semnum,int num,unsigned short *val) {
00056   unsigned short x[num];
00057   union semun n;
00058 
00059   memset(x,0,num * sizeof(unsigned short));
00060   memset(&n,0,sizeof(n));
00061 
00062   n.array = x;
00063 
00064   if(semctl(id,0,GETALL,n) == -1) return -1;
00065 
00066   *val = x[semnum];
00067 
00068   return 0;
00069 }
00070 
00071 /* eof */

Generated on Sun Apr 25 16:37:39 2004 for Classic Forum by doxygen 1.3.5