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_time_slice_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 time slice change function */
44 /* call. */
45 /* */
46 /* INPUT */
47 /* */
48 /* thread_ptr Pointer to thread */
49 /* new_time_slice New time slice */
50 /* old_time_slice Old time slice */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* TX_THREAD_ERROR Invalid thread pointer */
55 /* TX_CALLER_ERROR Invalid caller of function */
56 /* status Actual completion status */
57 /* */
58 /* CALLS */
59 /* */
60 /* _tx_thread_time_slice_change Actual time-slice change */
61 /* function */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Application Code */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
72 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* */
75 /**************************************************************************/
_txe_thread_time_slice_change(TX_THREAD * thread_ptr,ULONG new_time_slice,ULONG * old_time_slice)76 UINT _txe_thread_time_slice_change(TX_THREAD *thread_ptr, ULONG new_time_slice, ULONG *old_time_slice)
77 {
78
79 UINT status;
80
81
82 /* Check for an invalid thread pointer. */
83 if (thread_ptr == TX_NULL)
84 {
85
86 /* Thread pointer is invalid, return appropriate error code. */
87 status = TX_THREAD_ERROR;
88 }
89
90 /* Now check for invalid thread ID. */
91 else if (thread_ptr -> tx_thread_id != TX_THREAD_ID)
92 {
93
94 /* Thread pointer is invalid, return appropriate error code. */
95 status = TX_THREAD_ERROR;
96 }
97
98 /* Check for a valid old time-slice pointer. */
99 else if (old_time_slice == TX_NULL)
100 {
101
102 /* Invalid destination pointer, return appropriate error code. */
103 status = TX_PTR_ERROR;
104 }
105
106 /* Check for invalid caller of this function. */
107 else if (TX_THREAD_GET_SYSTEM_STATE() != ((ULONG) 0))
108 {
109
110 /* Invalid caller of this function, return appropriate error code. */
111 status = TX_CALLER_ERROR;
112 }
113 else
114 {
115
116 /* Call actual change time slice function. */
117 status = _tx_thread_time_slice_change(thread_ptr, new_time_slice, old_time_slice);
118 }
119
120 /* Return completion status. */
121 return(status);
122 }
123
124