1/* 2 * Copyright (c) 2004, Intel Corporation. All rights reserved. 3 * This file is licensed under the GPL license. For the full content 4 * of this license, see the COPYING file at the top level of this 5 * source tree. 6 * adam.li@intel.com 7 * 8 */ 9 10 /* Set the sched parameter with pthread_setschedparam() then get */ 11#include <pthread.h> 12#include <stdio.h> 13#include <stdlib.h> 14#include "posixtest.h" 15 16void *a_thread_func() 17{ 18 struct sched_param sparam; 19 int policy, priority, policy_1; 20 int rc; 21 22 policy = SCHED_FIFO; 23 priority = sched_get_priority_min(policy); 24 sparam.sched_priority = priority; 25 26 rc = pthread_setschedparam(pthread_self(), policy, &sparam); 27 if (rc != 0) 28 { 29 printf("Error at pthread_setschedparam: rc=%d\n", rc); 30 exit(PTS_FAIL); 31 } 32 rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam); 33 if (rc != 0) 34 { 35 printf("Error at pthread_getschedparam: rc=%d\n", rc); 36 exit(PTS_UNRESOLVED); 37 } 38 //printf("policy: %d, priority: %d\n", policy_1, sparam.sched_priority); 39 if (policy_1 != policy || sparam.sched_priority != priority) 40 { 41 printf("pthread_getschedparam did not get the correct value\n"); 42 exit(PTS_FAIL); 43 } 44 45 pthread_exit(0); 46 return NULL; 47} 48 49int main() 50{ 51 pthread_t new_th; 52 53 if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) 54 { 55 perror("Error creating thread\n"); 56 return PTS_UNRESOLVED; 57 } 58 59 pthread_join(new_th, NULL); 60 printf("Test PASSED\n"); 61 return PTS_PASS; 62} 63 64 65