1 #ifndef THREADS_SYNCH_H
2 #define THREADS_SYNCH_H
7 /* A counting semaphore. */
10 unsigned value; /* Current value. */
11 struct list waiters; /* List of waiting threads. */
14 void sema_init (struct semaphore *, unsigned value);
15 void sema_down (struct semaphore *);
16 bool sema_try_down (struct semaphore *);
17 void sema_up (struct semaphore *);
18 void sema_self_test (void);
23 struct thread *holder; /* Thread holding lock (for debugging). */
24 struct semaphore semaphore; /* Binary semaphore controlling access. */
27 void lock_init (struct lock *);
28 void lock_acquire (struct lock *);
29 bool lock_try_acquire (struct lock *);
30 void lock_release (struct lock *);
31 bool lock_held_by_current_thread (const struct lock *);
33 /* Condition variable. */
36 struct list waiters; /* List of waiting threads. */
39 void cond_init (struct condition *);
40 void cond_wait (struct condition *, struct lock *);
41 void cond_signal (struct condition *, struct lock *);
42 void cond_broadcast (struct condition *, struct lock *);
44 /* Optimization barrier.
46 The compiler will not reorder operations across an
47 optimization barrier. See "Optimization Barriers" in the
48 reference guide for more information.*/
49 #define barrier() asm volatile ("" : : : "memory")
51 #endif /* threads/synch.h */