Comment fixes.
[pintos-anon] / src / tests / threads / priority-donate-one.c
1 /* Based on a test originally submitted for Stanford's CS 140 in
2    winter 1999 by Matt Franklin <startled@leland.stanford.edu>,
3    Greg Hutchins <gmh@leland.stanford.edu>, Yu Ping Hu
4    <yph@cs.stanford.edu>.  Modified by arens. */
5
6 #include <stdio.h>
7 #include "tests/threads/tests.h"
8 #include "threads/init.h"
9 #include "threads/synch.h"
10 #include "threads/thread.h"
11
12 static thread_func acquire1_thread_func;
13 static thread_func acquire2_thread_func;
14
15 void
16 test_priority_donate_one (void) 
17 {
18   struct lock lock;
19
20   /* This test does not work with the MLFQS. */
21   ASSERT (!enable_mlfqs);
22
23   /* Make sure our priority is the default. */
24   ASSERT (thread_get_priority () == PRI_DEFAULT);
25
26   lock_init (&lock);
27   lock_acquire (&lock);
28   thread_create ("acquire1", PRI_DEFAULT - 1, acquire1_thread_func, &lock);
29   msg ("This thread should have priority %d.  Actual priority: %d.",
30        PRI_DEFAULT - 1, thread_get_priority ());
31   thread_create ("acquire2", PRI_DEFAULT - 2, acquire2_thread_func, &lock);
32   msg ("This thread should have priority %d.  Actual priority: %d.",
33        PRI_DEFAULT - 2, thread_get_priority ());
34   lock_release (&lock);
35   msg ("acquire2, acquire1 must already have finished, in that order.");
36   msg ("This should be the last line before finishing this test.");
37 }
38
39 static void
40 acquire1_thread_func (void *lock_) 
41 {
42   struct lock *lock = lock_;
43
44   lock_acquire (lock);
45   msg ("acquire1: got the lock");
46   lock_release (lock);
47   msg ("acquire1: done");
48 }
49
50 static void
51 acquire2_thread_func (void *lock_) 
52 {
53   struct lock *lock = lock_;
54
55   lock_acquire (lock);
56   msg ("acquire2: got the lock");
57   lock_release (lock);
58   msg ("acquire2: done");
59 }