Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

messup

  • Loading branch information...
commit 221141252334e3d73da09fbb00d4ce477fdb5098 1 parent dd45c83
@grantborthwick authored
View
7 src/threads/synch.c
@@ -228,6 +228,8 @@ lock_acquire (struct lock *lock)
sema_down (&lock->semaphore);
lock->holder = thread_current ();
+ list_push_front(&(thread_current ()->locks), lock);
+ lock->location = list_front(&(thread_current ()->locks));
}
/* Tries to acquires LOCK and returns true if successful or false
@@ -247,6 +249,8 @@ lock_try_acquire (struct lock *lock)
success = sema_try_down (&lock->semaphore);
if (success)
lock->holder = thread_current ();
+ list_push_front(&(thread_current ()->locks), lock);
+ lock->location = list_front(&(thread_current ()->locks));
return success;
}
@@ -260,9 +264,10 @@ lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
-
+ list_remove(lock->location);
lock->holder = NULL;
sema_up (&lock->semaphore);
+ //todo check if higher priority thread exists.
}
/* Returns true if the current thread holds LOCK, false
View
1  src/threads/synch.h
@@ -22,6 +22,7 @@ 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
1  src/threads/thread.c
@@ -497,6 +497,7 @@ init_thread (struct thread *t, const char *name, int priority)
t->magic = THREAD_MAGIC;
list_push_back (&all_list, &t->allelem);
sema_init(&t->sema_wakeup, 0);
+ list_init(&(thread_current ()->locks));
}
View
1  src/threads/thread.h
@@ -95,6 +95,7 @@ struct thread
/* Shared between thread.c and synch.c. */
struct list_elem elem; /* List element. */
struct list_elem timer_list_elem;
+ struct list locks;
#ifdef USERPROG
/* Owned by userprog/process.c. */
uint32_t *pagedir; /* Page directory. */

0 comments on commit 2211412

Please sign in to comment.
Something went wrong with that request. Please try again.