-
Notifications
You must be signed in to change notification settings - Fork 0
/
semops.c
79 lines (65 loc) · 1.46 KB
/
semops.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include<stdio.h>
#include<unistd.h>
#include<stdlib.h>
#include<sys/wait.h>
#include <time.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <stdbool.h>
#include <sys/msg.h>
struct MyInvites{
long mtype;
int vote;
int group;
}myInvite;
struct MyResposnes{
long mtype;
bool responese;
}myResponse;
struct Groups{
int size ;
int leader;
int mSize;
bool full;
}group;
struct Students {
int turn;
int id;
int vote;
int groupSize;
bool assigned;
bool closedGrouop;
}student;
union semun {
int val;
struct semid_ds* buf;
unsigned short* array;
#if defined(__linux__)
struct seminfo* __buf;
#endif
};
struct sembuf* generateReduceOp(){
struct sembuf* semReduce = malloc(sizeof(struct sembuf)*1);
struct sembuf* decrementOp = &semReduce[0];
decrementOp->sem_num = 0;
decrementOp->sem_op = -1;
decrementOp->sem_flg = 0;
return semReduce;
}
struct sembuf* generateWaitOp(){
struct sembuf* semWait = malloc(sizeof(struct sembuf)*1);
struct sembuf* waitOp = &semWait[0];
waitOp->sem_num = 0;
waitOp->sem_op = 0;
waitOp->sem_flg = 0;
return semWait;
}
struct sembuf* generateIncreaseOp(){
struct sembuf* semIncrease = malloc(sizeof(struct sembuf)*1);
struct sembuf* increaseOp = &semIncrease[0];
increaseOp->sem_num = 0;
increaseOp->sem_op = 1;
increaseOp->sem_flg = 0;
return semIncrease;
}