1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** ThreadX Component */
16 /** */
17 /** Thread */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22 #define TX_SOURCE_CODE
23
24
25 /* Include necessary system files. */
26
27 #include "tx_api.h"
28 #include "tx_thread.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _txe_thread_priority_change PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* William E. Lamie, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function checks for errors in the change priority function */
44 /* call. */
45 /* */
46 /* INPUT */
47 /* */
48 /* thread_ptr Pointer to thread to suspend */
49 /* new_priority New thread priority */
50 /* old_priority Old thread priority */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* TX_THREAD_ERROR Invalid thread pointer */
55 /* TX_PTR_ERROR Invalid old priority pointer */
56 /* TX_CALLER_ERROR Invalid caller of function */
57 /* status Actual completion status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _tx_thread_priority_change Actual priority change */
62 /* 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_priority_change(TX_THREAD * thread_ptr,UINT new_priority,UINT * old_priority)77 UINT _txe_thread_priority_change(TX_THREAD *thread_ptr, UINT new_priority, UINT *old_priority)
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 priority pointer. */
100 else if (old_priority == TX_NULL)
101 {
102
103 /* Invalid destination pointer, return appropriate error code. */
104 status = TX_PTR_ERROR;
105 }
106
107 /* Determine if the priority is legal. */
108 else if (new_priority >= ((UINT) TX_MAX_PRIORITIES))
109 {
110
111 /* Return an error status. */
112 status = TX_PRIORITY_ERROR;
113 }
114
115 /* Check for invalid caller of this function. */
116 else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
117 {
118
119 /* Invalid caller of this function, return appropriate error code. */
120 status = TX_CALLER_ERROR;
121 }
122 else
123 {
124
125 /* Call actual change thread priority function. */
126 status = _tx_thread_priority_change(thread_ptr, new_priority, old_priority);
127 }
128
129 /* Return completion status. */
130 return(status);
131 }
132
133