Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: CIS520/Pintos
base: 5e46279643
...
head fork: CIS520/Pintos
compare: 8c19809781
  • 1 commit
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Oct 06, 2012
Cfinley101 Cfinley101 FUCK IT 8c19809
Showing with 67 additions and 62 deletions.
  1. +65 −60 src/threads/synch.c
  2. +0 −1  src/threads/synch.h
  3. +2 −1  src/threads/thread.h
125 src/threads/synch.c
View
@@ -223,67 +223,48 @@ lock_acquire (struct lock *lock)
ASSERT (!lock_held_by_current_thread (lock));
struct thread *current = thread_current();
-
+ struct thread *locked = lock->holder;
+
+ //Disable Interupts
+ //enum intr_level old_level = intr_disable();
+
+ //Check if lock is aquired
if (!lock_try_acquire(lock))
{
- int current_thread_priority = thread_get_priority();
- int lock_holder_priority = lock->holder->priority;
- if (current_thread_priority > lock_holder_priority)
+ //Donate our priority if ours is higher
+ if (current->priority > locked->priority)
{
- lock_donate_priority(lock, lock->holder);
- //lock->holder->original_priority = lock_holder_priority;
- //lock->holder->priority = current_thread_priority;
-
+ //lock_donate_priority(lock, lock->holder);
+ lock->holder->original_priority = lock->holder->priority;
+ locked->priority = current->priority;
}
+
sema_down (&lock->semaphore);
lock->holder = thread_current ();
}
-
- /*ASSERT (lock != NULL);
- ASSERT (!intr_context ());
- ASSERT (!lock_held_by_current_thread (lock));
- struct thread *current = thread_current();
-
- enum intr_level old_level = intr_disable();
-
- if(!lock_try_acquire(lock))
- {
-
- while((current->priority > lock->holder->priority) && current != NULL)
- lock_donate_priority(lock);
- //reorder_ready_list();
- sema_down(&lock->semaphore);
- lock->holder = current;
- }*/
- current->lock_donated = NULL;
- //list_insert_ordered(&current->locks, &lock->lock_elem, &compare_lock_priority, NULL);
+ //current->lock_donated = NULL;
+ //list_insert_ordered(&current->donors, &lock->lock_elem, &compare_thread_priority, NULL);
//intr_set_level(old_level);
}
void
lock_donate_priority(struct lock *lock, struct thread *locked)
{
- struct thread *current = thread_current();
-
-
- lock->holder->original_priority = lock->holder->priority;
- //lock->holder->priority = current_thread_priority;
-
-
- //current->lock_donated = lock;
+ struct thread *current = thread_current();
+ current->lock_donated = lock;
+ current->donated = lock->holder;
locked->priority = current->priority;
- if(locked->lock_donated != NULL)
+ //adds the current thread to the locked thread's list of donors
+ list_push_front(&locked->donors, current);
+
+ //Recursive call to increase priority of all locked threads
+ if(!list_empty(locked->lock_donated))
{
lock_donate_priority(lock, locked->lock_donated);
}
-
- /*if(locked->lock_donated != NULL && current->status == THREAD_BLOCKED)
- {
- lock = locked->lock_donated;
- locked = lock->holder;
- }*/
+
}
/* Tries to acquires LOCK and returns true if successful or false
@@ -316,38 +297,54 @@ lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
- enum intr_level old_level = intr_disable();
- struct semaphore *sema = &(lock->semaphore);
- lock_revoke_priority(lock, lock->holder);
+
+ struct thread *current = thread_current();
+
+ //enum intr_level old_level = intr_disable();
+ //struct semaphore *sema = &(lock->semaphore);
+
+ //lock_revoke_priority(lock, lock->holder);
+ //lock->holder->priority = lock->holder->original_priority;
+
+ //current->priority = current->original_priority;
+
+ if (current->original_priority != -1)
+ {
+ thread_current()->priority = thread_current()->original_priority;
+ thread_current()->original_priority = -1;
+ }
+
lock->holder = NULL;
sema_up (&lock->semaphore);
- intr_set_level(old_level);
+ //intr_set_level(old_level);
}
void
lock_revoke_priority(struct lock *lock, struct thread *donatee)
{
struct thread* current = thread_current();
- donatee->priority = donatee->original_priority;
- while(!list_empty(&donatee->locks))
+ list_pop_front(donatee->donors);
+
+ struct thread *test = list_front(&donatee->donors); //(list_max(&ready_list, &compare_thread_priority, NULL), struct thread, elem) , struct thread, ->priority;
+ donatee->priority = test->priority;
+
+ while(!list_empty(&donatee->donors))
{
- lock_revoke_priority(lock, list_pop_front(&donatee->locks));
+ lock_revoke_priority(lock, list_pop_front(&donatee->donors));
+ //struct thread *temp = list_pop_front(&donatee->donors);
+ //lock_revoke_priority(lock, temp);
}
+
+ donatee->lock_donated = NULL;
+ //13 OUT OF 29
- /*struct thread *current = thread_current();
- struct lock * temp_lock;
-
- list_remove(&lock->lock_elem);
-
- if(list_empty(&current->locks))
- thread_set_priority(current->original_priority);
+ //struct thread* current = thread_current();
+
+
+
- else
- {
- temp_lock = list_entry(list_back(&current->locks), struct lock, lock_elem);
- }*/
}
/* Returns true if the current thread holds LOCK, false
@@ -443,3 +440,11 @@ cond_broadcast (struct condition *cond, struct lock *lock)
while (!list_empty (&cond->waiters))
cond_signal (cond, lock);
}
+/*void
+lock_donate_priority(struct lock *lock, struct thread *locked)
+ if(locked->lock_donated != NULL && current->status == THREAD_BLOCKED)
+ {
+ lock = locked->lock_donated;
+ locked = lock->holder;
+ }
+}*/
1  src/threads/synch.h
View
@@ -30,7 +30,6 @@ struct lock
{
struct thread *holder; /* Thread holding lock (for debugging). */
struct semaphore semaphore; /* Binary semaphore controlling access. */
- int lock_priority;
struct list_elem lock_elem;
};
3  src/threads/thread.h
View
@@ -97,7 +97,8 @@ struct thread
struct list_elem timer_elems; /* Timer list of elements */
struct semaphore sema; /* Semaphore struct. */
- struct list locks;
+ struct list *donors;
+ struct thread *donated;
struct lock *lock_donated;
int64_t wakeup_time; /* Wakeup time. */

No commit comments for this range

Something went wrong with that request. Please try again.