one (!).
thread_wake() needs to run with interrupts off.
struct thread_elem te;
te.thread = thread_current ();
list_push_back (&sema->waiters, &te.elem);
struct thread_elem te;
te.thread = thread_current ();
list_push_back (&sema->waiters, &te.elem);
}
sema->value--;
intr_set_level (old_level);
}
sema->value--;
intr_set_level (old_level);
old_level = intr_disable ();
if (!list_empty (&sema->waiters))
old_level = intr_disable ();
if (!list_empty (&sema->waiters))
- thread_wake (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);
}
sema->value++;
intr_set_level (old_level);
}
sf->eip = switch_entry;
/* Add to run queue. */
sf->eip = switch_entry;
/* Add to run queue. */
sf->eip = switch_entry;
/* Add to run queue. */
sf->eip = switch_entry;
/* Add to run queue. */
-/* Transitions T from its current state to THREAD_READY, the
- ready-to-run state. On entry, T must be ready or blocked.
+/* Transitions a blocked thread T from its current state to the
+ ready-to-run state. If T is not blocked, there is no effect.
(Use thread_yield() to make the running thread ready.) */
void
(Use thread_yield() to make the running thread ready.) */
void
-thread_wake (struct thread *t)
+thread_unblock (struct thread *t)
+ enum intr_level old_level;
+
- ASSERT (t->status == THREAD_READY || t->status == THREAD_BLOCKED);
- if (t->status != THREAD_READY)
+
+ old_level = intr_disable ();
+ if (t->status == THREAD_BLOCKED)
{
list_push_back (&run_queue, &t->rq_elem);
t->status = THREAD_READY;
}
{
list_push_back (&run_queue, &t->rq_elem);
t->status = THREAD_READY;
}
+ intr_set_level (old_level);
}
/* Returns the name of thread T. */
}
/* Returns the name of thread T. */
}
/* Puts the current thread to sleep. It will not be scheduled
}
/* Puts the current thread to sleep. It will not be scheduled
- again until awoken by thread_wake(). */
+ again until awoken by thread_unblock(). */
{
ASSERT (!intr_context ());
ASSERT (intr_get_level () == INTR_OFF);
{
ASSERT (!intr_context ());
ASSERT (intr_get_level () == INTR_OFF);
/* Let someone else run. */
intr_disable ();
/* Let someone else run. */
intr_disable ();
ASSERT (intr_get_level () == INTR_OFF);
cur->status = THREAD_RUNNING;
ASSERT (intr_get_level () == INTR_OFF);
cur->status = THREAD_RUNNING;
- if (prev != NULL && prev->status == THREAD_DYING)
- destroy_thread (prev);
#ifdef USERPROG
addrspace_activate (cur);
#endif
#ifdef USERPROG
addrspace_activate (cur);
#endif
+
+ if (prev != NULL && prev->status == THREAD_DYING)
+ destroy_thread (prev);
}
/* Schedules a new process. At entry, interrupts must be off and
}
/* Schedules a new process. At entry, interrupts must be off and
bool thread_execute (const char *filename);
#endif
bool thread_execute (const char *filename);
#endif
-void thread_wake (struct thread *);
+void thread_unblock (struct thread *);
const char *thread_name (struct thread *);
struct thread *thread_current (void);
void thread_exit (void) NO_RETURN;
void thread_yield (void);
const char *thread_name (struct thread *);
struct thread *thread_current (void);
void thread_exit (void) NO_RETURN;
void thread_yield (void);
-void thread_sleep (void);
+void thread_block (void);
- if (t->pagedir != NULL)
- pagedir_activate (t->pagedir);
+ pagedir_activate (t->pagedir);
tss_set_esp0 ((uint8_t *) t + PGSIZE);
}
tss_set_esp0 ((uint8_t *) t + PGSIZE);
}