X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Fsynch.h;h=a19e88b181dff1208839ff890154aa69b299ce91;hb=a03618133f7df0954802a470a4bee7674f7aed45;hp=ad8423891bad260215a77d0274dddfd75c960962;hpb=0cb604040a1fc50bba532deec45d945150633fe3;p=pintos-anon diff --git a/src/threads/synch.h b/src/threads/synch.h index ad84238..a19e88b 100644 --- a/src/threads/synch.h +++ b/src/threads/synch.h @@ -7,15 +7,14 @@ /* A counting semaphore. */ struct semaphore { - char name[16]; /* Name (for debugging purposes only). */ unsigned value; /* Current value. */ struct list waiters; /* List of waiting threads. */ }; -void sema_init (struct semaphore *, unsigned value, const char *); +void sema_init (struct semaphore *, unsigned value); void sema_down (struct semaphore *); +bool sema_try_down (struct semaphore *); void sema_up (struct semaphore *); -const char *sema_name (const struct semaphore *); void sema_self_test (void); /* Lock. */ @@ -25,23 +24,28 @@ struct lock struct semaphore semaphore; /* Binary semaphore controlling access. */ }; -void lock_init (struct lock *, const char *); +void lock_init (struct lock *); void lock_acquire (struct lock *); +bool lock_try_acquire (struct lock *); void lock_release (struct lock *); bool lock_held_by_current_thread (const struct lock *); -const char *lock_name (const struct lock *); /* Condition variable. */ struct condition { - char name[16]; /* Name (for debugging purposes only). */ struct list waiters; /* List of waiting threads. */ }; -void cond_init (struct condition *, const char *); +void cond_init (struct condition *); void cond_wait (struct condition *, struct lock *); void cond_signal (struct condition *, struct lock *); void cond_broadcast (struct condition *, struct lock *); -const char *cond_name (const struct condition *); + +/* Optimization barrier. + + The compiler will not reorder operations across an + optimization barrier. See "Optimization Barriers" in the + reference guide for more information.*/ +#define barrier() asm volatile ("" : : : "memory") #endif /* threads/synch.h */