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 * The pthread_getschedparam( ) function shall retrieve the scheduling 9 * policy and scheduling parameters for the thread whose thread ID is 10 * given by thread and shall store those values in 11 * policy and param, respectively. The priority value returned from 12 * pthread_getschedparam( ) shall be 13 * the value specified by the most recent pthread_setschedparam( ), 14 * pthread_setschedprio( ), or pthread_create( ) call affecting the 15 * target thread. It shall not reflect any temporary adjustments to 16 * its priority as a result of any priority inheritance or ceiling functions. 17 * 18 */ 19 20 /* Set the sched parameter with pthread_setschedparam then get */ 21#include <pthread.h> 22#include <stdio.h> 23#include <stdlib.h> 24#include "posixtest.h" 25 26void *a_thread_func() 27{ 28 struct sched_param sparam; 29 int policy, priority, policy_1; 30 int rc; 31 32 policy = SCHED_FIFO; 33 priority = sched_get_priority_min(policy); 34 sparam.sched_priority = priority; 35 36 rc = pthread_setschedparam(pthread_self(), policy, &sparam); 37 if (rc != 0) 38 { 39 printf("Error at pthread_setschedparam: rc=%d\n", rc); 40 exit(PTS_UNRESOLVED); 41 } 42 rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam); 43 if (rc != 0) 44 { 45 printf("Error at pthread_getschedparam: rc=%d\n", rc); 46 exit(PTS_FAIL); 47 } 48 //printf("policy: %d, priority: %d\n", policy_1, sparam.sched_priority); 49 if (policy_1 != policy || sparam.sched_priority != priority) 50 { 51 printf("pthread_getschedparam did not get the correct value\n"); 52 exit(PTS_FAIL); 53 } 54 55 pthread_exit(0); 56 return NULL; 57} 58 59int main() 60{ 61 pthread_t new_th; 62 63 if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) 64 { 65 perror("Error creating thread\n"); 66 return PTS_UNRESOLVED; 67 } 68 69 pthread_join(new_th, NULL); 70 printf("Test PASSED\n"); 71 return PTS_PASS; 72} 73 74 75