Initial revision
[pintos-anon] / src / threads / synch.h
1 #ifndef HEADER_SYNCH_H
2 #define HEADER_SYNCH_H 1
3
4 #include <stdbool.h>
5 #include "list.h"
6
7 struct semaphore 
8   {
9     char name[16];
10     unsigned value;
11     struct list waiters;
12   };
13
14 void sema_init (struct semaphore *, unsigned value, const char *);
15 void sema_down (struct semaphore *);
16 void sema_up (struct semaphore *);
17 const char *sema_name (const struct semaphore *);
18 void sema_self_test (void);
19
20 struct lock 
21   {
22     char name[16];
23     struct thread *holder;
24     struct semaphore semaphore;
25   };
26
27 void lock_init (struct lock *, const char *);
28 void lock_acquire (struct lock *);
29 void lock_release (struct lock *);
30 bool lock_held_by_current_thread (const struct lock *);
31 const char *lock_name (const struct lock *);
32
33 struct condition 
34   {
35     char name[16];
36     struct list waiters;
37   };
38
39 void cond_init (struct condition *, const char *);
40 void cond_wait (struct condition *, struct lock *);
41 void cond_signal (struct condition *, struct lock *);
42 void cond_broadcast (struct condition *, struct lock *);
43 const char *cond_name (const struct condition *);
44
45 #endif /* synch.h */