X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?p=pintos-anon;a=blobdiff_plain;f=src%2Fthreads%2Fsynch.h;h=53a5ee488cf07c83f68a7b136bc6506136180ac9;hp=c13f95d8d429a762843824e8c4e70fc1f6d4a799;hb=615bf3b3d2a8573ed6fb9ddc0055745e163ac999;hpb=5780c9f434cca090f88463b7f0199d49b4ded288 diff --git a/src/threads/synch.h b/src/threads/synch.h index c13f95d..53a5ee4 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 *name); +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,27 @@ struct lock struct semaphore semaphore; /* Binary semaphore controlling access. */ }; -void lock_init (struct lock *, const char *name); +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 *name); +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 *); + +/* Memory barrier. + + The compiler will not reorder operations that access memory + across a memory barrier. */ +#define barrier() asm volatile ("") #endif /* threads/synch.h */