summaryrefslogtreecommitdiffstats
path: root/threads
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-05-10 02:28:35 +0200
committermanuel <manuel@mausz.at>2012-05-10 02:28:35 +0200
commit2aaf7251b5191920d0880010c1cb30fb56f92c14 (patch)
tree540791e152ded80d0530f4b983de1d4ee77b9768 /threads
parent57c893ae56f151efc96fabebbb4c8ec039cb56ef (diff)
downloadprogos-2aaf7251b5191920d0880010c1cb30fb56f92c14.tar.gz
progos-2aaf7251b5191920d0880010c1cb30fb56f92c14.tar.bz2
progos-2aaf7251b5191920d0880010c1cb30fb56f92c14.zip
fix sema_up() and hence the priority-sema testcase => 2/18 failed
+ some minor documentation and cleanup stuff
Diffstat (limited to 'threads')
-rw-r--r--threads/synch.c20
-rw-r--r--threads/thread.h2
2 files changed, 7 insertions, 15 deletions
diff --git a/threads/synch.c b/threads/synch.c
index 92008ef..2cb4805 100644
--- a/threads/synch.c
+++ b/threads/synch.c
@@ -116,24 +116,21 @@ void
116sema_up (struct semaphore *sema) 116sema_up (struct semaphore *sema)
117{ 117{
118 enum intr_level old_level; 118 enum intr_level old_level;
119 bool yield = false; 119 struct thread *t = NULL;
120 120
121 ASSERT (sema != NULL); 121 ASSERT (sema != NULL);
122 122
123 old_level = intr_disable (); 123 old_level = intr_disable ();
124 if (!list_empty (&sema->waiters)) 124 while (!list_empty (&sema->waiters))
125 { 125 {
126 struct thread *t = list_entry (list_pop_front (&sema->waiters), 126 t = list_entry (list_pop_front (&sema->waiters), struct thread, elem);
127 struct thread, elem);
128 thread_unblock (t); 127 thread_unblock (t);
129 /* thread_unblock() doesn't yield so check if there's a need */
130 if (t->priority > thread_current ()->priority)
131 yield = true;
132 } 128 }
133 sema->value++; 129 sema->value++;
134 intr_set_level (old_level); 130 intr_set_level (old_level);
135 131
136 if (yield) 132 /* thread_unblock() doesn't yield so check if there's a need */
133 if (t != NULL && t->priority > thread_current ()->priority)
137 thread_yield(); 134 thread_yield();
138} 135}
139 136
@@ -228,8 +225,6 @@ lock_acquire (struct lock *lock)
228 225
229 if (lock->holder != NULL) 226 if (lock->holder != NULL)
230 { 227 {
231 //printf("[%d] acquire: lock=%p prio=%d\n", cur->tid, lock, cur->priority);
232
233 /* check for a possible priority donation */ 228 /* check for a possible priority donation */
234 if (cur->priority > lock->priority) 229 if (cur->priority > lock->priority)
235 { 230 {
@@ -291,18 +286,15 @@ lock_release (struct lock *lock)
291 ASSERT (lock_held_by_current_thread (lock)); 286 ASSERT (lock_held_by_current_thread (lock));
292 287
293 lock->holder = NULL; 288 lock->holder = NULL;
294 //lock->priority = we don't care as the next lock_acquire ()-call does 289 //lock->priority = we don't care as the next lock_acquire()-call does
295 sema_up (&lock->semaphore); 290 sema_up (&lock->semaphore);
296 291
297 /* we don't hold the lock any longer so remove it from the lock list */ 292 /* we don't hold the lock any longer so remove it from the lock list */
298 list_remove (&lock->elem); 293 list_remove (&lock->elem);
299 294
300 if (list_empty (&cur->locks)) 295 if (list_empty (&cur->locks))
301 {
302 //printf("[%d] restoring prio from %d to %d\n", cur->tid, cur->priority, cur->saved_priority);
303 /* we don't hold another lock so restore our base priority */ 296 /* we don't hold another lock so restore our base priority */
304 thread_donation_pass_back (); 297 thread_donation_pass_back ();
305 }
306 else 298 else
307 { 299 {
308 /* we still hold at least one lock so change our priority to the priority of the lock */ 300 /* we still hold at least one lock so change our priority to the priority of the lock */
diff --git a/threads/thread.h b/threads/thread.h
index 8bc6512..8cfafe6 100644
--- a/threads/thread.h
+++ b/threads/thread.h
@@ -110,7 +110,7 @@ struct thread
110 110
111 int is_donated; /* flag if threads priority has been donated by another thread */ 111 int is_donated; /* flag if threads priority has been donated by another thread */
112 int saved_priority; /* saved base priority in case of priority dontation */ 112 int saved_priority; /* saved base priority in case of priority dontation */
113 struct list locks; /* list of locks we currently hold */ 113 struct list locks; /* list of locks the thread currently holds */
114 }; 114 };
115 115
116/* If false (default), use round-robin scheduler. 116/* If false (default), use round-robin scheduler.