-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsemamore.h
41 lines (30 loc) · 967 Bytes
/
semamore.h
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
/**
* Luscious Locks Lab
* CS 241 - Fall 2016
*/
#include <pthread.h>
/**
* Changes to this file will be ignored when grading!
* For grading purposes, you can assume max_val won't equal 0.
*/
/**
* The struct for a Semamore.
* It contains the value the Semaphore is initially, as well as its maximum
* value (before it should block).
* Also contains an associated mutex and condition variable.
*/
typedef struct {
int value, max_val;
pthread_mutex_t m;
pthread_cond_t cv;
} Semamore;
// Initializes the members of the Semamore struct.
void semm_init(Semamore *s, int value, int max_val);
// Blocks when value is at 0, then decrememnts the value once it is not at 0.
void semm_wait(Semamore *s);
// Blocks when value is at max_val, then increments the value once it is not at
// max_val.
void semm_post(Semamore *s);
// Cleans up associated memory with the struct, but does not free the struct
// itself.
void semm_destroy(Semamore *s);