Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

get old benefactors

  • Loading branch information...
commit df9bb237dfe647d8fe7c694ef0ffcce50fe50d97 1 parent 55af3b1
@grantborthwick authored
View
16 src/threads/synch.c
@@ -118,17 +118,15 @@ sema_up (struct semaphore *sema)
struct list_elem* t;
struct thread* e2;
struct thread* t2 = NULL;
- //printf("1. [");
for (e = (list_begin (&(sema->waiters))); e!= list_end (&(sema->waiters));
e = list_next(e))
{
e2 = list_entry (e, struct thread, elem);
- //printf("(%d)%s\n",(e2->priority),(e2->name));
if (t2==NULL||(e2->priority)>(t2->priority)){
t = e;
t2 = e2;
- }
- }
+ }
+ }
list_remove(t);
for (e = (list_begin (&(sema->waiters))); e!= list_end (&(sema->waiters));
e = list_next(e))
@@ -236,6 +234,15 @@ lock_acquire (struct lock *lock)
thread_current ()->donee = NULL;
thread_current ()->want_lock = NULL;
lock->holder = thread_current ();
+ struct list_elem *e = list_begin (&((lock->semaphore).waiters));
+ struct thread * t;
+ while (e != list_end (&((lock->semaphore).waiters)))
+ {
+ if (e!= NULL){list_push_front(&(thread_current ()->benefactors),e);}
+ e = list_next(e);
+ }
+ thread_get_priority();
+
}
/* Tries to acquires LOCK and returns true if successful or false
@@ -279,6 +286,7 @@ lock_release (struct lock *lock)
if ((t->want_lock) == lock){e = list_remove(e);}
else{e = list_next(e);}
}
+
sema_up (&lock->semaphore);
}
View
12 src/threads/thread.c
@@ -370,7 +370,8 @@ thread_foreach (thread_action_func *func, void *aux)
void
thread_set_priority (int new_priority)
{
- thread_current ()->priority = new_priority;
+ thread_current ()->original_priority = new_priority;
+ thread_get_priority();
thread_check_yield ();
}
@@ -378,7 +379,14 @@ thread_set_priority (int new_priority)
int
thread_get_priority (void)
{
- //todo recursive with list or number check
+ /*struct list_elem *e;
+ struct thread * t;
+ for (e = list_begin (&); e != list_end (&);
+ e = list_next (e))
+ {
+ struct thread *t = list_entry (e, struct thread, allelem);
+ func (t, aux);
+ }*/
return thread_current ()->priority;
}
View
12 src/threads/thread.c~
@@ -370,7 +370,8 @@ thread_foreach (thread_action_func *func, void *aux)
void
thread_set_priority (int new_priority)
{
- thread_current ()->priority = new_priority;
+ thread_current ()->origional_priority = new_priority;
+ thread_get_priority();
thread_check_yield ();
}
@@ -378,7 +379,14 @@ thread_set_priority (int new_priority)
int
thread_get_priority (void)
{
- //todo recursive with list or number check
+ /*struct list_elem *e;
+ struct thread * t;
+ for (e = list_begin (&); e != list_end (&);
+ e = list_next (e))
+ {
+ struct thread *t = list_entry (e, struct thread, allelem);
+ func (t, aux);
+ }*/
return thread_current ()->priority;
}
View
2  src/threads/thread.h~
@@ -89,6 +89,7 @@ struct thread
char name[16]; /* Name (for debugging purposes). */
uint8_t *stack; /* Saved stack pointer. */
int priority; /* Priority. */
+ int original_priority; /* Base level thread priority */
struct list_elem allelem; /* List element for all threads list. */
int64_t wakeup_time;
struct semaphore sema_wakeup;
@@ -139,6 +140,7 @@ void thread_foreach (thread_action_func *, void *);
int thread_get_priority (void);
void thread_set_priority (int);
+void thread_re
int thread_get_nice (void);
void thread_set_nice (int);
Please sign in to comment.
Something went wrong with that request. Please try again.