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_trace.h"
30 #include "tx_thread.h"
31 #include "tx_timer.h"
32
33
34 /**************************************************************************/
35 /* */
36 /* FUNCTION RELEASE */
37 /* */
38 /* _tx_thread_time_slice_change PORTABLE C */
39 /* 6.1 */
40 /* AUTHOR */
41 /* */
42 /* William E. Lamie, Microsoft Corporation */
43 /* */
44 /* DESCRIPTION */
45 /* */
46 /* This function processes thread time slice change requests. The */
47 /* previous time slice is returned to the caller. If the new request */
48 /* is made for an executing thread, it is also placed in the actual */
49 /* time-slice countdown variable. */
50 /* */
51 /* INPUT */
52 /* */
53 /* thread_ptr Pointer to thread */
54 /* new_time_slice New time slice */
55 /* old_time_slice Old time slice */
56 /* */
57 /* OUTPUT */
58 /* */
59 /* status Service return status */
60 /* */
61 /* CALLS */
62 /* */
63 /* None */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Application Code */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 William E. Lamie Initial Version 6.0 */
74 /* 09-30-2020 Yuxin Zhou Modified comment(s), */
75 /* resulting in version 6.1 */
76 /* */
77 /**************************************************************************/
_tx_thread_time_slice_change(TX_THREAD * thread_ptr,ULONG new_time_slice,ULONG * old_time_slice)78 UINT _tx_thread_time_slice_change(TX_THREAD *thread_ptr, ULONG new_time_slice, ULONG *old_time_slice)
79 {
80
81 TX_INTERRUPT_SAVE_AREA
82
83 TX_THREAD *current_thread;
84
85
86 /* Lockout interrupts while the thread is being resumed. */
87 TX_DISABLE
88
89 /* If trace is enabled, insert this event into the trace buffer. */
90 TX_TRACE_IN_LINE_INSERT(TX_TRACE_THREAD_TIME_SLICE_CHANGE, thread_ptr, new_time_slice, thread_ptr -> tx_thread_new_time_slice, 0, TX_TRACE_THREAD_EVENTS)
91
92 /* Log this kernel call. */
93 TX_EL_THREAD_TIME_SLICE_CHANGE_INSERT
94
95 /* Return the old time slice. */
96 *old_time_slice = thread_ptr -> tx_thread_new_time_slice;
97
98 /* Setup the new time-slice. */
99 thread_ptr -> tx_thread_time_slice = new_time_slice;
100 thread_ptr -> tx_thread_new_time_slice = new_time_slice;
101
102 /* Pickup thread pointer. */
103 TX_THREAD_GET_CURRENT(current_thread)
104
105 /* Determine if this thread is the currently executing thread. */
106 if (thread_ptr == current_thread)
107 {
108
109 /* Yes, update the time-slice countdown variable. */
110 _tx_timer_time_slice = new_time_slice;
111 }
112
113 /* Restore interrupts. */
114 TX_RESTORE
115
116 /* Return completion status. */
117 return(TX_SUCCESS);
118 }
119
120