Advertisement
Guest User

Untitled

a guest
Feb 19th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. #ifndef THREADS_SYNCH_H
  2. #define THREADS_SYNCH_H
  3.  
  4. #include <list.h>
  5. #include <stdbool.h>
  6.  
  7. /* A counting semaphore. */
  8. struct semaphore
  9. {
  10. unsigned value; /* Current value. */
  11. struct list waiters; /* List of waiting threads. */
  12. };
  13.  
  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);
  19.  
  20. /* Lock. */
  21. struct lock
  22. {
  23. struct thread *holder; /* Thread holding lock. */
  24. struct semaphore semaphore; /* Binary semaphore controlling access. */
  25. };
  26.  
  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 *);
  32.  
  33. /* Condition variable. */
  34. struct condition
  35. {
  36. struct list waiters; /* List of waiting threads. */
  37. };
  38.  
  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 *);
  43.  
  44. int compare_cond_priority(struct list_elem *,struct list_elem *, void *);
  45.  
  46. /* Optimization barrier.
  47.  
  48. The compiler will not reorder operations across an
  49. optimization barrier. See "Optimization Barriers" in the
  50. reference guide for more information.*/
  51. #define barrier() asm volatile ("" : : : "memory")
  52.  
  53. #endif /* threads/synch.h */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement