summaryrefslogtreecommitdiffstats
path: root/threads/thread.c
diff options
context:
space:
mode:
Diffstat (limited to 'threads/thread.c')
-rw-r--r--threads/thread.c51
1 files changed, 25 insertions, 26 deletions
diff --git a/threads/thread.c b/threads/thread.c
index a7db106..358d3a1 100644
--- a/threads/thread.c
+++ b/threads/thread.c
@@ -367,12 +367,12 @@ thread_set_priority (int new_priority)
367 return; 367 return;
368 368
369 if (cur->is_donated) 369 if (cur->is_donated)
370 { 370 {
371 cur->saved_priority = new_priority; 371 cur->saved_priority = new_priority;
372 /* make sure we don't lower a donated priority */ 372 /* make sure we don't lower a donated priority */
373 if (new_priority < cur->priority) 373 if (new_priority < cur->priority)
374 return; 374 return;
375 } 375 }
376 thread_other_set_priority (cur, new_priority); 376 thread_other_set_priority (cur, new_priority);
377} 377}
378 378
@@ -387,18 +387,18 @@ thread_other_set_priority (struct thread *t, int new_priority)
387 t->priority = new_priority; 387 t->priority = new_priority;
388 388
389 if (t->status == THREAD_READY) 389 if (t->status == THREAD_READY)
390 { 390 {
391 /* sort our ordered list */ 391 /* sort our ordered list */
392 list_remove (&t->elem); 392 list_remove (&t->elem);
393 list_insert_ordered (&ready_list, &t->elem, &thread_priority_cmp_greater, NULL); 393 list_insert_ordered (&ready_list, &t->elem, &thread_priority_cmp_greater, NULL);
394 } 394 }
395 else if (t->status == THREAD_RUNNING && !list_empty (&ready_list)) 395 else if (t->status == THREAD_RUNNING && !list_empty (&ready_list))
396 { 396 {
397 /* compare priority with the highest priority in the list */ 397 /* compare priority with the highest priority in the list */
398 struct thread *t2 = list_entry (list_front (&ready_list), struct thread, elem); 398 struct thread *t2 = list_entry (list_front (&ready_list), struct thread, elem);
399 if (t2->priority > t->priority) 399 if (t2->priority > t->priority)
400 thread_yield (); 400 thread_yield ();
401 } 401 }
402} 402}
403 403
404void 404void
@@ -413,21 +413,20 @@ thread_donate_priority (struct thread *donator, struct thread *donee)
413 413
414 /* store our base priority */ 414 /* store our base priority */
415 if (!donee->is_donated) 415 if (!donee->is_donated)
416 { 416 {
417 donee->saved_priority = donee->priority; 417 donee->saved_priority = donee->priority;
418 donee->is_donated = true; 418 donee->is_donated = true;
419 } 419 }
420 thread_other_set_priority (donee, donator->priority); 420 thread_other_set_priority (donee, donator->priority);
421} 421}
422 422
423void 423void
424thread_donation_pass_back (void) 424thread_donation_pass_back (void)
425{ 425{
426 if (thread_current ()->is_donated) 426 if (!thread_current ()->is_donated)
427 { 427 return;
428 thread_current ()->is_donated = false; 428 thread_current ()->is_donated = false;
429 thread_set_priority (thread_current ()->saved_priority); 429 thread_set_priority (thread_current ()->saved_priority);
430 }
431} 430}
432 431
433/* Returns the current thread's priority. */ 432/* Returns the current thread's priority. */