Fix syn-read, syn-write, and always free elements from donors_list
This commit is contained in:
@@ -212,6 +212,7 @@ donate_priority (struct thread *donee) {
|
|||||||
ASSERT (intr_get_level () == INTR_OFF);
|
ASSERT (intr_get_level () == INTR_OFF);
|
||||||
|
|
||||||
struct thread *donor = thread_current ();
|
struct thread *donor = thread_current ();
|
||||||
|
list_remove (&donor->donor_elem);
|
||||||
list_push_back (&donee->donors_list, &donor->donor_elem);
|
list_push_back (&donee->donors_list, &donor->donor_elem);
|
||||||
|
|
||||||
while (donee != NULL)
|
while (donee != NULL)
|
||||||
@@ -342,7 +343,6 @@ lock_release (struct lock *lock)
|
|||||||
released, transfer the remaining orphaned donors to its donor list. */
|
released, transfer the remaining orphaned donors to its donor list. */
|
||||||
if (max_donor != NULL)
|
if (max_donor != NULL)
|
||||||
{
|
{
|
||||||
list_remove (&max_donor->donor_elem);
|
|
||||||
while (!list_empty (&orphan_list))
|
while (!list_empty (&orphan_list))
|
||||||
list_push_back (&max_donor->donors_list, list_pop_front (&orphan_list));
|
list_push_back (&max_donor->donors_list, list_pop_front (&orphan_list));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -373,7 +373,9 @@ thread_exit (void)
|
|||||||
and schedule another process. That process will destroy us
|
and schedule another process. That process will destroy us
|
||||||
when it calls thread_schedule_tail(). */
|
when it calls thread_schedule_tail(). */
|
||||||
intr_disable ();
|
intr_disable ();
|
||||||
list_remove (&thread_current()->allelem);
|
struct thread *t = thread_current ();
|
||||||
|
list_remove (&t->allelem);
|
||||||
|
list_remove (&t->donor_elem);
|
||||||
thread_current ()->status = THREAD_DYING;
|
thread_current ()->status = THREAD_DYING;
|
||||||
schedule ();
|
schedule ();
|
||||||
NOT_REACHED ();
|
NOT_REACHED ();
|
||||||
@@ -679,6 +681,7 @@ init_thread (struct thread *t, const char *name, int nice, int priority,
|
|||||||
t->base_priority
|
t->base_priority
|
||||||
= thread_mlfqs ? calculate_bsd_priority (recent_cpu, nice) : priority;
|
= thread_mlfqs ? calculate_bsd_priority (recent_cpu, nice) : priority;
|
||||||
list_init (&t->donors_list);
|
list_init (&t->donors_list);
|
||||||
|
list_push_back (&t->donors_list, &t->donor_elem);
|
||||||
t->waiting_lock = NULL;
|
t->waiting_lock = NULL;
|
||||||
|
|
||||||
t->nice = nice;
|
t->nice = nice;
|
||||||
|
|||||||
@@ -133,12 +133,11 @@ start_process (void *proc_start_data)
|
|||||||
/* Prevent writing to the file being executed. */
|
/* Prevent writing to the file being executed. */
|
||||||
struct file *exec_file = filesys_open (data->file_name);
|
struct file *exec_file = filesys_open (data->file_name);
|
||||||
thread_current ()->exec_file = exec_file;
|
thread_current ()->exec_file = exec_file;
|
||||||
file_deny_write(exec_file);
|
file_deny_write (exec_file);
|
||||||
|
lock_release (&filesys_lock);
|
||||||
|
|
||||||
success = load (data->file_name, &if_.eip, &if_.esp);
|
success = load (data->file_name, &if_.eip, &if_.esp);
|
||||||
|
|
||||||
lock_release (&filesys_lock);
|
|
||||||
|
|
||||||
/* If load failed, quit. */
|
/* If load failed, quit. */
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
@@ -326,7 +325,13 @@ process_exit (void)
|
|||||||
uint32_t *pd;
|
uint32_t *pd;
|
||||||
|
|
||||||
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
|
printf ("%s: exit(%d)\n", cur->name, cur->exit_status);
|
||||||
|
if (cur->exec_file != NULL)
|
||||||
|
{
|
||||||
|
lock_acquire (&filesys_lock);
|
||||||
|
file_allow_write (cur->exec_file);
|
||||||
file_close (cur->exec_file);
|
file_close (cur->exec_file);
|
||||||
|
lock_release (&filesys_lock);
|
||||||
|
}
|
||||||
|
|
||||||
/* Update process result. */
|
/* Update process result. */
|
||||||
if (cur->result != NULL)
|
if (cur->result != NULL)
|
||||||
@@ -486,6 +491,7 @@ load (const char *file_name, void (**eip) (void), void **esp)
|
|||||||
off_t file_ofs;
|
off_t file_ofs;
|
||||||
bool success = false;
|
bool success = false;
|
||||||
int i;
|
int i;
|
||||||
|
lock_acquire (&filesys_lock);
|
||||||
|
|
||||||
/* Allocate and activate page directory. */
|
/* Allocate and activate page directory. */
|
||||||
t->pagedir = pagedir_create ();
|
t->pagedir = pagedir_create ();
|
||||||
@@ -585,6 +591,7 @@ load (const char *file_name, void (**eip) (void), void **esp)
|
|||||||
done:
|
done:
|
||||||
/* We arrive here whether the load is successful or not. */
|
/* We arrive here whether the load is successful or not. */
|
||||||
file_close (file);
|
file_close (file);
|
||||||
|
lock_release (&filesys_lock);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user