1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | #if HAVE_CONFIG_H1 |
15 | #include "config.h" |
16 | #endif |
17 | |
18 | #include <rtems/system.h> |
19 | #include <rtems/rtems/status.h> |
20 | #include <rtems/rtems/support.h> |
21 | #include <rtems/rtems/modes.h> |
22 | #include <rtems/score/object.h> |
23 | #include <rtems/score/stack.h> |
24 | #include <rtems/score/states.h> |
25 | #include <rtems/rtems/tasks.h> |
26 | #include <rtems/score/thread.h> |
27 | #include <rtems/score/threadq.h> |
28 | #include <rtems/score/tod.h> |
29 | #include <rtems/score/userext.h> |
30 | #include <rtems/score/wkspace.h> |
31 | #include <rtems/score/apiext.h> |
32 | #include <rtems/score/sysstate.h> |
33 | |
34 | |
35 | |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | |
42 | |
43 | |
44 | |
45 | |
46 | |
47 | |
48 | |
49 | |
50 | rtems_status_code rtems_task_mode( |
51 | rtems_mode mode_set, |
52 | rtems_mode mask, |
53 | rtems_mode *previous_mode_set |
54 | ) |
55 | { |
56 | Thread_Control *executing; |
57 | RTEMS_API_Control *api; |
58 | ASR_Information *asr; |
59 | bool_Bool is_asr_enabled = false0; |
60 | bool_Bool needs_asr_dispatching = false0; |
61 | rtems_mode old_mode; |
62 | |
63 | if ( !previous_mode_set ) |
64 | return RTEMS_INVALID_ADDRESS; |
65 | |
66 | executing = _Thread_Executing_Per_CPU_Information.executing; |
67 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
68 | asr = &api->Signal; |
69 | |
70 | old_mode = (executing->is_preemptible) ? RTEMS_PREEMPT0x00000000 : RTEMS_NO_PREEMPT0x00000100; |
71 | |
72 | if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE ) |
73 | old_mode |= RTEMS_NO_TIMESLICE0x00000000; |
74 | else |
75 | old_mode |= RTEMS_TIMESLICE0x00000200; |
76 | |
77 | old_mode |= (asr->is_enabled) ? RTEMS_ASR0x00000000 : RTEMS_NO_ASR0x00000400; |
78 | old_mode |= _ISR_Get_level()_CPU_ISR_Get_level(); |
79 | |
80 | *previous_mode_set = old_mode; |
81 | |
82 | |
83 | |
84 | |
85 | if ( mask & RTEMS_PREEMPT_MASK0x00000100 ) |
86 | executing->is_preemptible = _Modes_Is_preempt(mode_set) ? true1 : false0; |
87 | |
88 | if ( mask & RTEMS_TIMESLICE_MASK0x00000200 ) { |
89 | if ( _Modes_Is_timeslice(mode_set) ) { |
90 | executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE; |
91 | executing->cpu_time_budget = _Thread_Ticks_per_timeslice; |
92 | } else |
93 | executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; |
94 | } |
95 | |
96 | |
97 | |
98 | |
99 | if ( mask & RTEMS_INTERRUPT_MASK0x0000000F ) |
100 | _Modes_Set_interrupt_level( mode_set ); |
101 | |
102 | |
103 | |
104 | |
105 | is_asr_enabled = false0; |
| Value stored to 'is_asr_enabled' is never read |
106 | needs_asr_dispatching = false0; |
107 | |
108 | if ( mask & RTEMS_ASR_MASK0x00000400 ) { |
109 | is_asr_enabled = _Modes_Is_asr_disabled( mode_set ) ? false0 : true1; |
110 | if ( is_asr_enabled != asr->is_enabled ) { |
111 | asr->is_enabled = is_asr_enabled; |
112 | _ASR_Swap_signals( asr ); |
113 | if ( _ASR_Are_signals_pending( asr ) ) { |
114 | needs_asr_dispatching = true1; |
115 | } |
116 | } |
117 | } |
118 | |
119 | if ( _System_state_Is_up( _System_state_Get() ) ) { |
120 | if (_Thread_Evaluate_is_dispatch_needed( needs_asr_dispatching ) ) |
121 | _Thread_Dispatch(); |
122 | } |
123 | |
124 | return RTEMS_SUCCESSFUL; |
125 | } |