-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrwlock.h
68 lines (55 loc) · 1.55 KB
/
rwlock.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
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
/**
* @File rwlock.h
*
* The header file that you need to implement for assignment 3.
*
* @author Andrew Quinn, Mitchell Elliott, and Gurpreet Dhillon.
*/
#pragma once
#include <stdint.h>
/** @struct rwlock_t
*
* @brief This typedef renames the struct rwlock. Your `c` file
* should define the variables that you need for your reader/writer
* lock.
*/
typedef struct rwlock rwlock_t;
typedef enum { READERS, WRITERS, N_WAY } PRIORITY;
/** @brief Dynamically allocates and initializes a new rwlock with
* priority p, and, if using N_WAY priority, n.
*
* @param The priority of the rwlock
*
* @param The n value, if using N_WAY priority
*
* @return a pointer to a new queue_t
*/
rwlock_t *rwlock_new(PRIORITY p, uint32_t n);
/** @brief Delete your rwlock and free all of its memory.
*
* @param rw the rwlock to be deleted. Note, you should assign the
* passed in pointer to NULL when returning (i.e., you should set *rw
* = NULL after deallocation).
*
*/
void rwlock_delete(rwlock_t **rw);
/** @brief acquire rw for reading
*
*/
void reader_lock(rwlock_t *rw);
/** @brief release rw for reading--you can assume that the thread
* releasing the lock has *already* acquired it for reading.
*
*/
void reader_unlock(rwlock_t *rw);
/** @brief acquire rw for writing
*
*/
void writer_lock(rwlock_t *rw);
/** @brief release rw for writing--you can assume that the thread
* releasing the lock has *already* acquired it for writing.
*
*/
void writer_unlock(rwlock_t *rw);
int reader_wait(rwlock_t *rw);
int writer_wait(rwlock_t *rw);