Redo makefiles.
[pintos-anon] / src / threads / synch.h
1 #ifndef HEADER_SYNCH_H
2 #define HEADER_SYNCH_H 1
3
4 #include <stdbool.h>
5 #include "lib/list.h"
6
7 /* A counting semaphore. */
8 struct semaphore 
9   {
10     char name[16];              /* Name (for debugging purposes only). */
11     unsigned value;             /* Current value. */
12     struct list waiters;        /* List of waiting threads. */
13   };
14
15 void sema_init (struct semaphore *, unsigned value, const char *);
16 void sema_down (struct semaphore *);
17 void sema_up (struct semaphore *);
18 const char *sema_name (const struct semaphore *);
19 void sema_self_test (void);
20
21 /* Lock. */
22 struct lock 
23   {
24     char name[16];              /* Name (for debugging purposes only). */
25     struct thread *holder;      /* Thread holding lock (for debugging). */
26     struct semaphore semaphore; /* Binary semaphore controlling access. */
27   };
28
29 void lock_init (struct lock *, const char *);
30 void lock_acquire (struct lock *);
31 void lock_release (struct lock *);
32 bool lock_held_by_current_thread (const struct lock *);
33 const char *lock_name (const struct lock *);
34
35 /* Condition variable. */
36 struct condition 
37   {
38     char name[16];              /* Name (for debugging purposes only). */
39     struct list waiters;        /* List of waiting threads. */
40   };
41
42 void cond_init (struct condition *, const char *);
43 void cond_wait (struct condition *, struct lock *);
44 void cond_signal (struct condition *, struct lock *);
45 void cond_broadcast (struct condition *, struct lock *);
46 const char *cond_name (const struct condition *);
47
48 #endif /* synch.h */