#include "synch.h"
#include "interrupt.h"
#include "lib.h"
-#include "malloc.h"
#include "thread.h"
/* One thread in a list. */
void
sema_down (struct semaphore *sema)
{
- enum if_level old_level;
+ enum intr_level old_level;
ASSERT (sema != NULL);
ASSERT (!intr_context ());
struct thread_elem te;
te.thread = thread_current ();
list_push_back (&sema->waiters, &te.elem);
- thread_sleep ();
+ thread_block ();
}
sema->value--;
intr_set_level (old_level);
void
sema_up (struct semaphore *sema)
{
- enum if_level old_level;
+ enum intr_level old_level;
ASSERT (sema != NULL);
old_level = intr_disable ();
if (!list_empty (&sema->waiters))
- thread_ready (list_entry (list_pop_front (&sema->waiters),
- struct thread_elem, elem)->thread);
+ thread_unblock (list_entry (list_pop_front (&sema->waiters),
+ struct thread_elem, elem)->thread);
sema->value++;
intr_set_level (old_level);
}
void
lock_acquire (struct lock *lock)
{
- enum if_level old_level;
+ enum intr_level old_level;
ASSERT (lock != NULL);
ASSERT (!intr_context ());
void
lock_release (struct lock *lock)
{
- enum if_level old_level;
+ enum intr_level old_level;
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));