X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Fsynch.h;h=9e464e3876400f60fafbc44a105f859ffd4b6938;hb=6d19139b337fcb7c9b31e5b6724e6ae19499e4c5;hp=d21ecff08ca546473cbfc7d84229fa5d54310fab;hpb=3625c2e6aba3b282f91282492c4b3fba324816c1;p=pintos-anon diff --git a/src/threads/synch.h b/src/threads/synch.h index d21ecff..9e464e3 100644 --- a/src/threads/synch.h +++ b/src/threads/synch.h @@ -1,48 +1,50 @@ -#ifndef HEADER_SYNCH_H -#define HEADER_SYNCH_H 1 +#ifndef THREADS_SYNCH_H +#define THREADS_SYNCH_H +#include #include -#include "list.h" /* 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. */ struct lock { - char name[16]; /* Name (for debugging purposes only). */ struct thread *holder; /* Thread holding lock (for debugging). */ 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 *); -#endif /* synch.h */ +/* Optimization barrier. + + The compiler will not reorder operations across an + optimization barrier. */ +#define barrier() asm volatile ("" : : : "memory") + +#endif /* threads/synch.h */