wip on hw4
This commit is contained in:
parent
c987ffa0dc
commit
77f94f0828
3 changed files with 22 additions and 3 deletions
|
@ -332,6 +332,15 @@ thread_create (const char *name, int priority,
|
||||||
|
|
||||||
intr_set_level (old_level);
|
intr_set_level (old_level);
|
||||||
|
|
||||||
|
// Update children list on parent and set parent pointer on child
|
||||||
|
struct thread* cur = thread_current();
|
||||||
|
|
||||||
|
ASSERT (cur != NULL);
|
||||||
|
|
||||||
|
//printf("Parent thread is: %s. Child is %s\n", cur->name, t->name);
|
||||||
|
list_push_back(&cur->children, &t->child_elem);
|
||||||
|
t->parent = cur;
|
||||||
|
|
||||||
/* Add to run queue. */
|
/* Add to run queue. */
|
||||||
thread_unblock (t);
|
thread_unblock (t);
|
||||||
|
|
||||||
|
@ -430,6 +439,7 @@ thread_exit (void)
|
||||||
list_remove (&t->allelem);
|
list_remove (&t->allelem);
|
||||||
thread_current ()->status = THREAD_DYING;
|
thread_current ()->status = THREAD_DYING;
|
||||||
sema_up(&t->waiting_sem);
|
sema_up(&t->waiting_sem);
|
||||||
|
list_remove(&t->child_elem);
|
||||||
schedule ();
|
schedule ();
|
||||||
NOT_REACHED ();
|
NOT_REACHED ();
|
||||||
}
|
}
|
||||||
|
@ -576,6 +586,7 @@ init_thread (struct thread *t, const char *name, int priority)
|
||||||
t->stack = (uint8_t *) t + PGSIZE;
|
t->stack = (uint8_t *) t + PGSIZE;
|
||||||
sema_init(&t->waiting_sem, 0);
|
sema_init(&t->waiting_sem, 0);
|
||||||
t->waited_on_before = 0;
|
t->waited_on_before = 0;
|
||||||
|
list_init(&t->children);
|
||||||
|
|
||||||
if (thread_mlfqs) {
|
if (thread_mlfqs) {
|
||||||
t->nice_init = priority > 20 || priority < 20 ? 0 : priority;
|
t->nice_init = priority > 20 || priority < 20 ? 0 : priority;
|
||||||
|
@ -717,12 +728,13 @@ schedule (void)
|
||||||
struct thread *
|
struct thread *
|
||||||
thread_get_by_tid (tid_t tid)
|
thread_get_by_tid (tid_t tid)
|
||||||
{
|
{
|
||||||
|
struct list* children = &thread_current()->children;
|
||||||
struct list_elem *e;
|
struct list_elem *e;
|
||||||
for (e = list_begin (&all_list);
|
for (e = list_begin (children);
|
||||||
e != list_end (&all_list);
|
e != list_end (children);
|
||||||
e = list_next (e))
|
e = list_next (e))
|
||||||
{
|
{
|
||||||
struct thread *t = list_entry (e, struct thread, allelem);
|
struct thread *t = list_entry (e, struct thread, child_elem);
|
||||||
if (t->tid == tid)
|
if (t->tid == tid)
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,10 +100,16 @@ struct thread
|
||||||
int nice;
|
int nice;
|
||||||
int nice_init;
|
int nice_init;
|
||||||
FPReal recent_cpu;
|
FPReal recent_cpu;
|
||||||
|
|
||||||
struct semaphore waiting_sem;
|
struct semaphore waiting_sem;
|
||||||
|
|
||||||
int exit_status;
|
int exit_status;
|
||||||
int waited_on_before;
|
int waited_on_before;
|
||||||
|
|
||||||
|
struct thread* parent;
|
||||||
|
struct list_elem child_elem;
|
||||||
|
struct list children;
|
||||||
|
|
||||||
#ifdef USERPROG
|
#ifdef USERPROG
|
||||||
/* Owned by userprog/process.c. */
|
/* Owned by userprog/process.c. */
|
||||||
uint32_t *pagedir; /* Page directory. */
|
uint32_t *pagedir; /* Page directory. */
|
||||||
|
|
|
@ -63,6 +63,7 @@ process_execute (const char *file_name)
|
||||||
tid = thread_create (program_name, PRI_DEFAULT, start_process, fn_copy);
|
tid = thread_create (program_name, PRI_DEFAULT, start_process, fn_copy);
|
||||||
if (tid == TID_ERROR)
|
if (tid == TID_ERROR)
|
||||||
palloc_free_page (fn_copy);
|
palloc_free_page (fn_copy);
|
||||||
|
|
||||||
return tid;
|
return tid;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in a new issue