diff options
author | rpj <rpj> | 2003-09-18 02:31:39 +0000 |
---|---|---|
committer | rpj <rpj> | 2003-09-18 02:31:39 +0000 |
commit | af1871fba4fc253b5a31e4a0eed667fe79f534d7 (patch) | |
tree | 1242599d7334ae50c5c05f9b23b52876e4287924 /tests/priority2.c | |
parent | fac679912b15dd89cafdb09bf873d7eacc80a05e (diff) |
Cleanup and fixes to thread priority management. Other minor changes.snap-2003-09-18
Diffstat (limited to 'tests/priority2.c')
-rw-r--r-- | tests/priority2.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/tests/priority2.c b/tests/priority2.c index 54fd3a0..fc19ed5 100644 --- a/tests/priority2.c +++ b/tests/priority2.c @@ -81,27 +81,31 @@ enum { int minPrio; int maxPrio; int validPriorities[PTW32TEST_MAXPRIORITIES]; -pthread_mutex_t startMx = PTHREAD_MUTEX_INITIALIZER; +pthread_barrier_t startBarrier, endBarrier; void * func(void * arg) { int policy; + int result; struct sched_param param; - assert(pthread_mutex_lock(&startMx) == 0); + result = pthread_barrier_wait(&startBarrier); + assert(result == 0 || result == PTHREAD_BARRIER_SERIAL_THREAD); assert(pthread_getschedparam(pthread_self(), &policy, ¶m) == 0); - assert(pthread_mutex_unlock(&startMx) == 0); assert(policy == SCHED_OTHER); + result = pthread_barrier_wait(&endBarrier); + assert(result == 0 || result == PTHREAD_BARRIER_SERIAL_THREAD); return (void *) param.sched_priority; } - + void * getValidPriorities(void * arg) { int prioSet; - pthread_t threadID = pthread_self(); - HANDLE threadH = pthread_getw32threadhandle_np(threadID); + pthread_t thread = pthread_self(); + HANDLE threadH = pthread_getw32threadhandle_np(thread); + struct sched_param param; for (prioSet = minPrio; prioSet <= maxPrio; @@ -112,8 +116,8 @@ getValidPriorities(void * arg) * from the previous value. Make the previous value a known * one so that we can check later. */ - SetThreadPriority(threadH, PTW32TEST_THREAD_INIT_PRIO); - SetThreadPriority(threadH, prioSet); + param.sched_priority = prioSet; + assert(pthread_setschedparam(thread, SCHED_OTHER, ¶m) == 0); validPriorities[prioSet+(PTW32TEST_MAXPRIORITIES/2)] = GetThreadPriority(threadH); } @@ -126,6 +130,7 @@ main() { pthread_t t; void * result = NULL; + int result2; struct sched_param param; assert((maxPrio = sched_get_priority_max(SCHED_OTHER)) != -1); @@ -134,6 +139,9 @@ main() assert(pthread_create(&t, NULL, getValidPriorities, NULL) == 0); assert(pthread_join(t, &result) == 0); + assert(pthread_barrier_init(&startBarrier, NULL, 2) == 0); + assert(pthread_barrier_init(&endBarrier, NULL, 2) == 0); + /* Set the thread's priority to a known initial value. * If the new priority is invalid then the threads priority * is unchanged from the previous value. @@ -145,13 +153,16 @@ main() param.sched_priority <= maxPrio; param.sched_priority++) { - assert(pthread_mutex_lock(&startMx) == 0); assert(pthread_create(&t, NULL, func, NULL) == 0); assert(pthread_setschedparam(t, SCHED_OTHER, ¶m) == 0); - assert(pthread_mutex_unlock(&startMx) == 0); - pthread_join(t, &result); - assert((int) result == + result2 = pthread_barrier_wait(&startBarrier); + assert(result2 == 0 || result2 == PTHREAD_BARRIER_SERIAL_THREAD); + result2 = pthread_barrier_wait(&endBarrier); + assert(result2 == 0 || result2 == PTHREAD_BARRIER_SERIAL_THREAD); + assert(GetThreadPriority(pthread_getw32threadhandle_np(t)) == validPriorities[param.sched_priority+(PTW32TEST_MAXPRIORITIES/2)]); + pthread_join(t, &result); + assert(param.sched_priority == (int)result); } return 0; |