merge process-wait
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include "threads/flags.h"
|
||||
#include "threads/interrupt.h"
|
||||
#include "threads/intr-stubs.h"
|
||||
#include "threads/malloc.h"
|
||||
#include "threads/palloc.h"
|
||||
#include "threads/switch.h"
|
||||
#include "threads/synch.h"
|
||||
@@ -70,6 +71,7 @@ static void kernel_thread (thread_func *, void *aux);
|
||||
static void idle (void *aux UNUSED);
|
||||
static struct thread *running_thread (void);
|
||||
static struct thread *next_thread_to_run (void);
|
||||
static void init_process_result (struct thread *t);
|
||||
static void init_thread (struct thread *, const char *name, int nice,
|
||||
int priority, fp32_t recent_cpu);
|
||||
static bool is_thread (struct thread *) UNUSED;
|
||||
@@ -112,6 +114,7 @@ thread_init (void)
|
||||
initial_thread_recent_cpu);
|
||||
initial_thread->status = THREAD_RUNNING;
|
||||
initial_thread->tid = allocate_tid ();
|
||||
initial_thread->result = NULL; /* Main thread cannot be waited for. */
|
||||
}
|
||||
|
||||
/* Starts preemptive thread scheduling by enabling interrupts.
|
||||
@@ -238,6 +241,7 @@ thread_create (const char *name, int priority,
|
||||
struct thread *parent_thread = thread_current ();
|
||||
init_thread (t, name, parent_thread->nice, priority, parent_thread->recent_cpu);
|
||||
tid = t->tid = allocate_tid ();
|
||||
init_process_result (t);
|
||||
|
||||
#ifdef USERPROG
|
||||
hash_init (&t->open_files, fd_hash, fd_less, NULL);
|
||||
@@ -265,6 +269,10 @@ thread_create (const char *name, int priority,
|
||||
|
||||
intr_set_level (old_level);
|
||||
|
||||
/* No need to synchronise child_results since it is only ever accessed by one
|
||||
thread. By the nature of increasing TIDs, this list is ordered. */
|
||||
list_push_back (&parent_thread->child_results, &t->result->elem);
|
||||
|
||||
/* Add to run queue. */
|
||||
thread_unblock (t);
|
||||
|
||||
@@ -638,6 +646,18 @@ is_thread (struct thread *t)
|
||||
return t != NULL && t->magic == THREAD_MAGIC;
|
||||
}
|
||||
|
||||
/* Allocate and initialise a process result for given thread. */
|
||||
static void
|
||||
init_process_result (struct thread *t)
|
||||
{
|
||||
struct process_result *result = malloc (sizeof (struct process_result));
|
||||
result->tid = t->tid;
|
||||
result->exit_status = t->exit_status;
|
||||
lock_init (&result->lock);
|
||||
sema_init (&result->sema, 0);
|
||||
t->result = result;
|
||||
}
|
||||
|
||||
/* Does basic initialization of T as a blocked thread named
|
||||
NAME. */
|
||||
static void
|
||||
@@ -666,6 +686,7 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
||||
t->priority = t->base_priority;
|
||||
|
||||
t->exit_status = -1;
|
||||
list_init (&t->child_results);
|
||||
|
||||
old_level = intr_disable ();
|
||||
list_push_back (&all_list, &t->allelem);
|
||||
|
||||
Reference in New Issue
Block a user