diff options
| author | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
|---|---|---|
| committer | manuel <manuel@mausz.at> | 2012-03-27 11:51:08 +0200 |
| commit | 4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch) | |
| tree | 868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /tests/threads/priority-donate-lower.c | |
| parent | eae0bd57f0a26314a94785061888d193d186944a (diff) | |
| download | progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2 progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip | |
reorganize file structure to match the upstream requirements
Diffstat (limited to 'tests/threads/priority-donate-lower.c')
| -rw-r--r-- | tests/threads/priority-donate-lower.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/tests/threads/priority-donate-lower.c b/tests/threads/priority-donate-lower.c new file mode 100644 index 0000000..4965d75 --- /dev/null +++ b/tests/threads/priority-donate-lower.c | |||
| @@ -0,0 +1,51 @@ | |||
| 1 | /* The main thread acquires a lock. Then it creates a | ||
| 2 | higher-priority thread that blocks acquiring the lock, causing | ||
| 3 | it to donate their priorities to the main thread. The main | ||
| 4 | thread attempts to lower its priority, which should not take | ||
| 5 | effect until the donation is released. */ | ||
| 6 | |||
| 7 | #include <stdio.h> | ||
| 8 | #include "tests/threads/tests.h" | ||
| 9 | #include "threads/init.h" | ||
| 10 | #include "threads/synch.h" | ||
| 11 | #include "threads/thread.h" | ||
| 12 | |||
| 13 | static thread_func acquire_thread_func; | ||
| 14 | |||
| 15 | void | ||
| 16 | test_priority_donate_lower (void) | ||
| 17 | { | ||
| 18 | struct lock lock; | ||
| 19 | |||
| 20 | /* This test does not work with the MLFQS. */ | ||
| 21 | ASSERT (!thread_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 ("acquire", PRI_DEFAULT + 10, acquire_thread_func, &lock); | ||
| 29 | msg ("Main thread should have priority %d. Actual priority: %d.", | ||
| 30 | PRI_DEFAULT + 10, thread_get_priority ()); | ||
| 31 | |||
| 32 | msg ("Lowering base priority..."); | ||
| 33 | thread_set_priority (PRI_DEFAULT - 10); | ||
| 34 | msg ("Main thread should have priority %d. Actual priority: %d.", | ||
| 35 | PRI_DEFAULT + 10, thread_get_priority ()); | ||
| 36 | lock_release (&lock); | ||
| 37 | msg ("acquire must already have finished."); | ||
| 38 | msg ("Main thread should have priority %d. Actual priority: %d.", | ||
| 39 | PRI_DEFAULT - 10, thread_get_priority ()); | ||
| 40 | } | ||
| 41 | |||
| 42 | static void | ||
| 43 | acquire_thread_func (void *lock_) | ||
| 44 | { | ||
| 45 | struct lock *lock = lock_; | ||
| 46 | |||
| 47 | lock_acquire (lock); | ||
| 48 | msg ("acquire: got the lock"); | ||
| 49 | lock_release (lock); | ||
| 50 | msg ("acquire: done"); | ||
| 51 | } | ||
