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 /** ThreadX Component */
17 /** */
18 /** Thread */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define TX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "tx_api.h"
29 #include "tx_thread.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _txe_thread_preemption_change PORTABLE C */
37 /* 6.1 */
38 /* AUTHOR */
39 /* */
40 /* William E. Lamie, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function checks for errors in the preemption threshold change */
45 /* function call. */
46 /* */
47 /* INPUT */
48 /* */
49 /* thread_ptr Pointer to thread */
50 /* new_threshold New preemption threshold */
51 /* old_threshold Old preemption threshold */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* TX_THREAD_ERROR Invalid thread pointer */
56 /* TX_PTR_ERROR Invalid old threshold pointer */
57 /* TX_CALLER_ERROR Invalid caller of function */
58 /* status Actual completion status */
59 /* */
60 /* CALLS */
61 /* */
62 /* _tx_thread_preemption_change Actual preempt change function*/
63 /* */
64 /* CALLED BY */
65 /* */
66 /* Application Code */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
73 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_txe_thread_preemption_change(TX_THREAD * thread_ptr,UINT new_threshold,UINT * old_threshold)77 UINT _txe_thread_preemption_change(TX_THREAD *thread_ptr, UINT new_threshold, UINT *old_threshold)
78 {
79
80 UINT status;
81
82
83 /* Check for an invalid thread pointer. */
84 if (thread_ptr == TX_NULL)
85 {
86
87 /* Thread pointer is invalid, return appropriate error code. */
88 status = TX_THREAD_ERROR;
89 }
90
91 /* Now check for invalid thread ID. */
92 else if (thread_ptr -> tx_thread_id != TX_THREAD_ID)
93 {
94
95 /* Thread pointer is invalid, return appropriate error code. */
96 status = TX_THREAD_ERROR;
97 }
98
99 /* Check for a valid old threshold pointer. */
100 else if (old_threshold == TX_NULL)
101 {
102
103 /* Invalid destination pointer, return appropriate error code. */
104 status = TX_PTR_ERROR;
105 }
106
107 /* Check for invalid caller of this function. */
108 else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
109 {
110
111 /* Invalid caller of this function, return appropriate error code. */
112 status = TX_CALLER_ERROR;
113 }
114
115 /* Determine if the preemption-threshold is valid. */
116 else if (new_threshold > thread_ptr -> tx_thread_user_priority)
117 {
118
119 /* Return an error status. */
120 status = TX_THRESH_ERROR;
121 }
122 else
123 {
124
125 /* Call actual change thread preemption function. */
126 status = _tx_thread_preemption_change(thread_ptr, new_threshold, old_threshold);
127 }
128
129 /* Return completion status. */
130 return(status);
131 }
132
133