1 /**************************************************************************/ 2 /* */ 3 /* Copyright (c) Microsoft Corporation. All rights reserved. */ 4 /* */ 5 /* This software is licensed under the Microsoft Software License */ 6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */ 7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */ 8 /* and in the root directory of this software. */ 9 /* */ 10 /**************************************************************************/ 11 12 13 /**************************************************************************/ 14 /**************************************************************************/ 15 /** */ 16 /** POSIX wrapper for THREADX */ 17 /** */ 18 /** */ 19 /** */ 20 /**************************************************************************/ 21 /**************************************************************************/ 22 23 /* Include necessary system files. */ 24 25 #include "tx_api.h" /* Threadx API */ 26 #include "pthread.h" /* Posix API */ 27 #include "px_int.h" /* Posix helper functions */ 28 29 30 /**************************************************************************/ 31 /* */ 32 /* FUNCTION RELEASE */ 33 /* */ 34 /* pthread_setschedparam PORTABLE C */ 35 /* 6.1.7 */ 36 /* AUTHOR */ 37 /* */ 38 /* William E. Lamie, Microsoft Corporation */ 39 /* */ 40 /* DESCRIPTION */ 41 /* */ 42 /* This function changes the scheduling parameters of a pthread. */ 43 /* */ 44 /* */ 45 /* INPUT */ 46 /* */ 47 /* thread POSIX thread ID */ 48 /* policy Address of the thread attributes */ 49 /* sched_param Address of structure to contain the */ 50 /* returned scheduling parameters */ 51 /* */ 52 /* */ 53 /* OUTPUT */ 54 /* */ 55 /* 0 if successful */ 56 /* Value in case of any error */ 57 /* */ 58 /* CALLS */ 59 /* */ 60 /* posix_tid2tcb */ 61 /* posix_tcb2thread */ 62 /* tx_thread_priority_change */ 63 /* */ 64 /* */ 65 /* CALLED BY */ 66 /* */ 67 /* Application Code */ 68 /* */ 69 /* RELEASE HISTORY */ 70 /* */ 71 /* DATE NAME DESCRIPTION */ 72 /* */ 73 /* 06-02-2021 William E. Lamie Initial Version 6.1.7 */ 74 /* */ 75 /**************************************************************************/ pthread_setschedparam(pthread_t thread,INT policy,const struct sched_param * param)76INT pthread_setschedparam(pthread_t thread, INT policy, const struct sched_param *param) 77 { 78 TX_INTERRUPT_SAVE_AREA 79 POSIX_TCB *thread_tcb; 80 TX_THREAD *TheThread; 81 UINT Tmp; 82 ULONG UTmp; 83 84 85 86 thread_tcb=posix_tid2tcb(thread); 87 88 if(thread_tcb==NULL) 89 { 90 return(ESRCH); 91 } 92 if (!(( policy == SCHED_FIFO )||(policy== SCHED_RR))) 93 { 94 return(ENOTSUP); 95 } 96 97 98 TX_DISABLE 99 thread_tcb->sched_policy=policy; 100 thread_tcb->sched_attr.sched_priority=param->sched_priority; 101 thread_tcb->current_priority= param->sched_priority; 102 103 TheThread=posix_tcb2thread(thread_tcb); 104 105 tx_thread_priority_change(TheThread, (TX_LOWEST_PRIORITY - thread_tcb->current_priority + 1),&Tmp); 106 thread_tcb->orig_priority=(ULONG) Tmp; 107 108 if(policy==SCHED_RR) thread_tcb->time_slice=SCHED_RR_TIME_SLICE; 109 else thread_tcb->time_slice=0; 110 tx_thread_time_slice_change(TheThread, thread_tcb->time_slice, &UTmp); 111 112 TX_RESTORE 113 114 return(NO_ERROR); 115 } 116 117 118 119 120 121