Permalink
Browse files

gix

  • Loading branch information...
1 parent cc154e3 commit 99770017db1d13c6ac7603b98bb8069a4241e93d @grantborthwick committed Oct 5, 2012
Showing with 20 additions and 14 deletions.
  1. +0 −1 src/threads/synch.h
  2. +19 −13 src/threads/thread.c
  3. +1 −0 src/threads/thread.h
View
@@ -22,7 +22,6 @@ struct lock
{
struct thread *holder; /* Thread holding lock (for debugging). */
struct semaphore semaphore; /* Binary semaphore controlling access. */
- struct list_elem* location;
};
void lock_init (struct lock *);
View
@@ -331,6 +331,24 @@ thread_yield (void)
intr_set_level (old_level);
}
+
+void thread_check_yield ()
+{
+ struct list_elem* e;
+ struct thread* e2;
+ bool y = false;
+ for (e = (list_begin (&ready_list)); e!= list_end (&ready_list);
+ e = list_next(e))
+ {
+ e2 = list_entry (e, struct thread, elem);
+ if ((e2->priority) >(thread_current ()->priority)){
+ y = true;
+ break;
+ }
+ }
+ if (y){thread_yield();}
+}
+
/* Invoke function 'func' on all threads, passing along 'aux'.
This function must be called with interrupts off. */
void
@@ -354,19 +372,7 @@ thread_set_priority (int new_priority)
{
//todo check if lower than any ready thread.
thread_current ()->priority = new_priority;
- struct list_elem* e;
- struct thread* e2;
- bool y = false;
- for (e = (list_begin (&ready_list)); e!= list_end (&ready_list);
- e = list_next(e))
- {
- e2 = list_entry (e, struct thread, elem);
- if ((e2->priority) >(thread_current ()->priority)){
- y = true;
- break;
- }
- }
- if (y){thread_yield();}
+ thread_check_yield ();
}
/* Returns the current thread's priority. */
View
@@ -128,6 +128,7 @@ const char *thread_name (void);
void thread_exit (void) NO_RETURN;
void thread_yield (void);
+void thread_check_yield (void);
/* Performs some operation on thread t, given auxiliary data AUX. */
typedef void thread_action_func (struct thread *t, void *aux);

0 comments on commit 9977001

Please sign in to comment.