00001
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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
00042
00043
00044
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