diff --git a/src/threads/synch.c b/src/threads/synch.c index d773824..4bf54a6 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -187,6 +187,9 @@ lock_init (struct lock *lock) sema_init (&lock->semaphore, 1); } +static void +donate_priority (struct thread *donor, struct thread *donee); + /* Acquires LOCK, sleeping until it becomes available if necessary. The lock must not already be held by the current thread. @@ -202,8 +205,18 @@ lock_acquire (struct lock *lock) ASSERT (!intr_context ()); ASSERT (!lock_held_by_current_thread (lock)); + struct thread *t = thread_current (); + + /* TODO: If a high-priority thread holding a lock sleeps, this may cause a + race condition here or break the assumption that donation must occur. */ + if (lock->holder != NULL) + { + t->waiting_lock = lock; + } + sema_down (&lock->semaphore); lock->holder = thread_current (); + t->waiting_lock = NULL; } /* Tries to acquires LOCK and returns true if successful or false