#include "interrupt.h"
#include "intr-stubs.h"
#include "lib.h"
+#include "gdt.h"
#include "mmu.h"
#include "palloc.h"
#include "random.h"
struct kernel_thread_frame
{
void *eip; /* Return address. */
- void (*function) (void *); /* Function to call. */
+ thread_func *function; /* Function to call. */
void *aux; /* Auxiliary data for function. */
};
-static void kernel_thread (void (*function) (void *aux), void *aux);
+static void kernel_thread (thread_func *, void *aux);
static struct thread *next_thread_to_run (void);
static struct thread *new_thread (const char *name);
void
thread_init (void)
{
- ASSERT (intr_get_level () == IF_OFF);
+ ASSERT (intr_get_level () == INTR_OFF);
/* Initialize run queue. */
list_init (&run_queue);
semaphore or some other form of synchronization if you need to
ensure ordering. */
struct thread *
-thread_create (const char *name, void (*function) (void *aux), void *aux)
+thread_create (const char *name, thread_func *function, void *aux)
{
struct thread *t;
struct kernel_thread_frame *kf;
if (t == NULL)
return false;
- if (!addrspace_load (&t->addrspace, filename, &start))
+ if (!addrspace_load (t, filename, &start))
PANIC ("%s: program load failed", filename);
/* Interrupt frame. */
if_->ds = SEL_UDSEG;
if_->eip = start;
if_->cs = SEL_UCSEG;
- if_->eflags = FLAG_IF | 2;
+ if_->eflags = FLAG_IF | FLAG_MBS;
if_->esp = PHYS_BASE;
if_->ss = SEL_UDSEG;
thread_yield (void)
{
struct thread *cur = thread_current ();
- enum if_level old_level;
+ enum intr_level old_level;
ASSERT (!intr_context ());
thread_sleep (void)
{
ASSERT (!intr_context ());
- ASSERT (intr_get_level () == IF_OFF);
+ ASSERT (intr_get_level () == INTR_OFF);
thread_current ()->status = THREAD_BLOCKED;
schedule ();
/* Function used as the basis for a kernel thread. */
static void
-kernel_thread (void (*function) (void *aux), void *aux)
+kernel_thread (thread_func *function, void *aux)
{
ASSERT (function != NULL);
ASSERT (t->status == THREAD_DYING);
ASSERT (t != thread_current ());
+#ifdef USERPROG
+ addrspace_destroy (t);
+#endif
palloc_free (t);
}
{
struct thread *cur = thread_current ();
- ASSERT (intr_get_level () == IF_OFF);
+ 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->addrspace);
+ addrspace_activate (cur);
#endif
}
struct thread *cur = thread_current ();
struct thread *next = next_thread_to_run ();
- ASSERT (intr_get_level () == IF_OFF);
+ ASSERT (intr_get_level () == INTR_OFF);
ASSERT (cur->status != THREAD_RUNNING);
ASSERT (is_thread (next));