Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 1 commit
  • 3 files changed
  • 0 comments
  • 1 contributor
Oct 05, 2012
Cfinley101 FUCK IT 8c19809
125  src/threads/synch.c
@@ -223,67 +223,48 @@ lock_acquire (struct lock *lock)
223 223
   ASSERT (!lock_held_by_current_thread (lock));
224 224
 
225 225
   struct thread *current = thread_current();
226  
-
  226
+  struct thread *locked = lock->holder;
  227
+  
  228
+  //Disable Interupts
  229
+  //enum intr_level old_level = intr_disable();
  230
+  
  231
+  //Check if lock is aquired
227 232
   if (!lock_try_acquire(lock))
228 233
   {
229  
-	int current_thread_priority = thread_get_priority();
230  
-	int lock_holder_priority = lock->holder->priority;
231  
-	if (current_thread_priority > lock_holder_priority)
  234
+	//Donate our priority if ours is higher
  235
+	if (current->priority > locked->priority)
232 236
     {		
233  
-	  lock_donate_priority(lock, lock->holder);
234  
-	  //lock->holder->original_priority = lock_holder_priority;
235  
-	  //lock->holder->priority = current_thread_priority;
236  
-	  
  237
+	  //lock_donate_priority(lock, lock->holder);
  238
+	  lock->holder->original_priority = lock->holder->priority;
  239
+	  locked->priority = current->priority;
237 240
     }
  241
+
238 242
     sema_down (&lock->semaphore);
239 243
     lock->holder = thread_current ();
240 244
   }
241  
-  	
242  
-  /*ASSERT (lock != NULL);
243  
-  ASSERT (!intr_context ());
244  
-  ASSERT (!lock_held_by_current_thread (lock));
245  
-  struct thread *current = thread_current();
246  
-
247  
-  enum intr_level old_level = intr_disable();
248  
-
249  
-  if(!lock_try_acquire(lock))
250  
-  {
251  
-	   
252  
-	   while((current->priority > lock->holder->priority) && current != NULL)
253  
-			lock_donate_priority(lock);
254  
-	   //reorder_ready_list();
255  
-	   sema_down(&lock->semaphore);
256  
-	   lock->holder = current;
257  
-  }*/
258 245
   
259  
-  current->lock_donated = NULL;
260  
-  //list_insert_ordered(&current->locks, &lock->lock_elem, &compare_lock_priority, NULL);
  246
+  //current->lock_donated = NULL;
  247
+  //list_insert_ordered(&current->donors, &lock->lock_elem, &compare_thread_priority, NULL);
261 248
   //intr_set_level(old_level);
262 249
 }
263 250
 
264 251
 void
265 252
 lock_donate_priority(struct lock *lock, struct thread *locked)
266 253
 {
267  
-	struct thread *current = thread_current();
268  
-	
269  
-	
270  
-	lock->holder->original_priority = lock->holder->priority;
271  
-	  //lock->holder->priority = current_thread_priority;
272  
-	  
273  
-	  
274  
-	//current->lock_donated = lock;
  254
+	struct thread *current = thread_current();	
  255
+	current->lock_donated = lock;
  256
+	current->donated = lock->holder;
275 257
 	locked->priority = current->priority;
276 258
 	
277  
-	if(locked->lock_donated != NULL)
  259
+	//adds the current thread to the locked thread's list of donors
  260
+	list_push_front(&locked->donors, current);  
  261
+	
  262
+	//Recursive call to increase priority of all locked threads
  263
+	if(!list_empty(locked->lock_donated))
278 264
 	{
279 265
 		lock_donate_priority(lock, locked->lock_donated);
280 266
 	}
281  
-	
282  
-	/*if(locked->lock_donated != NULL && current->status == THREAD_BLOCKED)
283  
-	{
284  
-		lock = locked->lock_donated;
285  
-		locked = lock->holder;
286  
-	}*/
  267
+
287 268
 }
288 269
 
289 270
 /* Tries to acquires LOCK and returns true if successful or false
@@ -316,38 +297,54 @@ lock_release (struct lock *lock)
316 297
 {
317 298
   ASSERT (lock != NULL);
318 299
   ASSERT (lock_held_by_current_thread (lock));
319  
-  enum intr_level old_level = intr_disable();
320  
-  struct semaphore *sema = &(lock->semaphore);
321  
-  lock_revoke_priority(lock, lock->holder);
  300
+  
  301
+  struct thread *current = thread_current();
  302
+  
  303
+  //enum intr_level old_level = intr_disable();
  304
+  //struct semaphore *sema = &(lock->semaphore);
  305
+  
  306
+  //lock_revoke_priority(lock, lock->holder);
  307
+  //lock->holder->priority = lock->holder->original_priority;
  308
+  
  309
+  //current->priority = current->original_priority;
  310
+  
  311
+  if (current->original_priority != -1)
  312
+  {
  313
+	thread_current()->priority = thread_current()->original_priority;
  314
+	thread_current()->original_priority = -1;
  315
+  }
  316
+  
322 317
   lock->holder = NULL;
323 318
   sema_up (&lock->semaphore);
324  
-  intr_set_level(old_level);
  319
+  //intr_set_level(old_level);
325 320
 }
326 321
 
327 322
 void
328 323
 lock_revoke_priority(struct lock *lock, struct thread *donatee)
329 324
 {
330 325
 	struct thread* current = thread_current();
331  
-	donatee->priority = donatee->original_priority;
332  
-	while(!list_empty(&donatee->locks))
  326
+	list_pop_front(donatee->donors);
  327
+	
  328
+	struct thread *test = list_front(&donatee->donors);	//(list_max(&ready_list, &compare_thread_priority, NULL), struct thread, elem)			    , struct thread, ->priority;
  329
+	donatee->priority = test->priority;
  330
+	
  331
+	while(!list_empty(&donatee->donors))
333 332
 	{
334  
-		lock_revoke_priority(lock, list_pop_front(&donatee->locks));
  333
+		lock_revoke_priority(lock, list_pop_front(&donatee->donors));
  334
+		//struct thread *temp = list_pop_front(&donatee->donors);
  335
+		//lock_revoke_priority(lock, temp);
335 336
 	}
  337
+
  338
+	donatee->lock_donated = NULL;
336 339
 	
337 340
 		
  341
+	//13 OUT OF 29
338 342
 	
339  
-	/*struct thread *current = thread_current();
340  
-	struct lock * temp_lock;
341  
-	
342  
-	list_remove(&lock->lock_elem);
343  
-	
344  
-	if(list_empty(&current->locks))
345  
-		thread_set_priority(current->original_priority);
  343
+	//struct thread* current = thread_current();
  344
+
  345
+
  346
+
346 347
 	
347  
-	else
348  
-	{
349  
-		temp_lock = list_entry(list_back(&current->locks), struct lock, lock_elem);		
350  
-	}*/
351 348
 }
352 349
 
353 350
 /* Returns true if the current thread holds LOCK, false
@@ -443,3 +440,11 @@ cond_broadcast (struct condition *cond, struct lock *lock)
443 440
   while (!list_empty (&cond->waiters))
444 441
     cond_signal (cond, lock);
445 442
 }
  443
+/*void
  444
+lock_donate_priority(struct lock *lock, struct thread *locked)
  445
+	if(locked->lock_donated != NULL && current->status == THREAD_BLOCKED)
  446
+	{
  447
+		lock = locked->lock_donated;
  448
+		locked = lock->holder;
  449
+	}
  450
+}*/
1  src/threads/synch.h
@@ -30,7 +30,6 @@ struct lock
30 30
   {
31 31
     struct thread *holder;         /* Thread holding lock (for debugging). */
32 32
     struct semaphore semaphore; /* Binary semaphore controlling access. */
33  
-    int lock_priority;
34 33
     struct list_elem lock_elem;    
35 34
   };
36 35
 
3  src/threads/thread.h
@@ -97,7 +97,8 @@ struct thread
97 97
     struct list_elem timer_elems;	     /* Timer list of elements */
98 98
     struct semaphore sema;		     /* Semaphore struct. */
99 99
     
100  
-    struct list locks;
  100
+    struct list *donors;
  101
+    struct thread *donated;
101 102
     struct lock *lock_donated;
102 103
 
103 104
     int64_t wakeup_time;		/* Wakeup time. */

No commit comments for this range

Something went wrong with that request. Please try again.