Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / tests / threads / priority-condvar.c
1 #include <stdio.h>
2 #include "tests/threads/tests.h"
3 #include "threads/init.h"
4 #include "threads/malloc.h"
5 #include "threads/synch.h"
6 #include "threads/thread.h"
7 #include "devices/timer.h"
8
9 static thread_func priority_condvar_thread;
10 static struct lock lock;
11 static struct condition condition;
12
13 void
14 test_priority_condvar (void) 
15 {
16   int i;
17   
18   /* This test does not work with the MLFQS. */
19   ASSERT (!enable_mlfqs);
20
21   lock_init (&lock);
22   cond_init (&condition);
23
24   thread_set_priority (PRI_MAX);
25   for (i = 0; i < 10; i++) 
26     {
27       int priority = (i + 7) % 10 + PRI_DEFAULT + 1;
28       char name[16];
29       snprintf (name, sizeof name, "priority %d", priority);
30       thread_create (name, priority, priority_condvar_thread, NULL);
31     }
32
33   for (i = 0; i < 10; i++) 
34     {
35       lock_acquire (&lock);
36       msg ("Signaling...");
37       cond_signal (&condition, &lock);
38       lock_release (&lock);
39     }
40 }
41
42 static void
43 priority_condvar_thread (void *aux UNUSED) 
44 {
45   msg ("Thread %s starting.", thread_name ());
46   lock_acquire (&lock);
47   cond_wait (&condition, &lock);
48   msg ("Thread %s woke up.", thread_name ());
49   lock_release (&lock);
50 }