Skip to content
Browse files

pre donate

  • Loading branch information...
1 parent 53dbb3b commit 81ebaade0661059a0506a778c2e736d52dd0fdd7 @grantborthwick committed Oct 5, 2012
Showing with 23 additions and 4 deletions.
  1. +5 −2 src/threads/synch.c
  2. +17 −2 src/threads/thread.c
  3. +1 −0 src/threads/thread.h
View
7 src/threads/synch.c
@@ -228,6 +228,7 @@ lock_acquire (struct lock *lock)
sema_down (&lock->semaphore);
lock->holder = thread_current ();
+ //list_push_front(&(thread_current ()->locks), lock);
}
/* Tries to acquires LOCK and returns true if successful or false
@@ -245,8 +246,10 @@ lock_try_acquire (struct lock *lock)
ASSERT (!lock_held_by_current_thread (lock));
success = sema_try_down (&lock->semaphore);
- if (success)
+ if (success){
lock->holder = thread_current ();
+ //list_push_front(&(thread_current ()->locks), lock);
+ }
return success;
}
@@ -260,7 +263,7 @@ lock_release (struct lock *lock)
{
ASSERT (lock != NULL);
ASSERT (lock_held_by_current_thread (lock));
-
+ //thread_release_lock(lock);
lock->holder = NULL;
sema_up (&lock->semaphore);
}
View
19 src/threads/thread.c
@@ -258,6 +258,22 @@ thread_unblock (struct thread *t)
thread_yield();
}
}
+/* Releases a lock. */
+void thread_release_lock (struct lock* l)
+{
+ //printf("taking out of wait\n");
+ struct lock* e;
+ struct thread* e2;
+ /*for (e = (list_begin (&(thread_current ()->locks))); e!= list_end (&(thread_current ()->locks));
+ e = list_next(e))
+ {
+ //e2 = list_entry (e, struct lock, locks);
+ if (e == l){
+ list_remove(e);
+ break;
+ }
+ }*/
+}
/* Returns the name of the running thread. */
const char *
@@ -500,10 +516,9 @@ init_thread (struct thread *t, const char *name, int priority)
t->stack = (uint8_t *) t + PGSIZE;
t->priority = priority;
t->magic = THREAD_MAGIC;
+ list_init(&t->locks);
list_push_back (&all_list, &t->allelem);
sema_init(&t->sema_wakeup, 0);
-
-
}
/* Allocates a SIZE-byte frame at the top of thread T's stack and
View
1 src/threads/thread.h
@@ -121,6 +121,7 @@ tid_t thread_create (const char *name, int priority, thread_func *, void *);
void thread_block (void);
void thread_unblock (struct thread *);
+void thread_release_lock (struct lock*);
struct thread *thread_current (void);
tid_t thread_tid (void);

0 comments on commit 81ebaad

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