X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fthreads%2Fsynch.c;h=317c68ad501301538f47a697df7a8eaf02d4e077;hb=2dc702a30822c4773989f3bf5bc730848c0f473c;hp=79dcfb78c4832f6d908add061f8977f4c4110e28;hpb=615bf3b3d2a8573ed6fb9ddc0055745e163ac999;p=pintos-anon diff --git a/src/threads/synch.c b/src/threads/synch.c index 79dcfb7..317c68a 100644 --- a/src/threads/synch.c +++ b/src/threads/synch.c @@ -55,8 +55,8 @@ sema_init (struct semaphore *sema, unsigned value) This function may sleep, so it must not be called within an interrupt handler. This function may be called with - interrupts disabled, but interrupts will be turned back on if - we need to sleep. */ + interrupts disabled, but if it sleeps then the next scheduled + thread will probably turn interrupts back on. */ void sema_down (struct semaphore *sema) { @@ -192,16 +192,12 @@ lock_init (struct lock *lock) void lock_acquire (struct lock *lock) { - enum intr_level old_level; - ASSERT (lock != NULL); ASSERT (!intr_context ()); ASSERT (!lock_held_by_current_thread (lock)); - old_level = intr_disable (); sema_down (&lock->semaphore); lock->holder = thread_current (); - intr_set_level (old_level); } /* Tries to acquires LOCK and returns true if successful or false @@ -209,22 +205,18 @@ lock_acquire (struct lock *lock) thread. This function will not sleep, so it may be called within an - interupt handler. */ + interrupt handler. */ bool lock_try_acquire (struct lock *lock) { - enum intr_level old_level; bool success; ASSERT (lock != NULL); ASSERT (!lock_held_by_current_thread (lock)); - old_level = intr_disable (); success = sema_try_down (&lock->semaphore); if (success) lock->holder = thread_current (); - intr_set_level (old_level); - return success; } @@ -236,15 +228,11 @@ lock_try_acquire (struct lock *lock) void lock_release (struct lock *lock) { - enum intr_level old_level; - ASSERT (lock != NULL); ASSERT (lock_held_by_current_thread (lock)); - old_level = intr_disable (); lock->holder = NULL; sema_up (&lock->semaphore); - intr_set_level (old_level); } /* Returns true if the current thread holds LOCK, false