[c4d69e2] | 1 | /* |
---|
| 2 | * RTEMS Task Manager |
---|
| 3 | * |
---|
| 4 | * |
---|
[08311cc3] | 5 | * COPYRIGHT (c) 1989-1999. |
---|
[c4d69e2] | 6 | * On-Line Applications Research Corporation (OAR). |
---|
| 7 | * |
---|
| 8 | * The license and distribution terms for this file may be |
---|
| 9 | * found in the file LICENSE in this distribution or at |
---|
[277cc95] | 10 | * http://www.rtems.com/license/LICENSE. |
---|
[c4d69e2] | 11 | * |
---|
| 12 | * $Id$ |
---|
| 13 | */ |
---|
| 14 | |
---|
[1095ec1] | 15 | #if HAVE_CONFIG_H |
---|
| 16 | #include "config.h" |
---|
| 17 | #endif |
---|
| 18 | |
---|
[c4d69e2] | 19 | #include <rtems/system.h> |
---|
| 20 | #include <rtems/rtems/status.h> |
---|
| 21 | #include <rtems/rtems/support.h> |
---|
| 22 | #include <rtems/rtems/modes.h> |
---|
| 23 | #include <rtems/score/object.h> |
---|
| 24 | #include <rtems/score/stack.h> |
---|
| 25 | #include <rtems/score/states.h> |
---|
| 26 | #include <rtems/rtems/tasks.h> |
---|
| 27 | #include <rtems/score/thread.h> |
---|
| 28 | #include <rtems/score/threadq.h> |
---|
| 29 | #include <rtems/score/tod.h> |
---|
| 30 | #include <rtems/score/userext.h> |
---|
| 31 | #include <rtems/score/wkspace.h> |
---|
| 32 | #include <rtems/score/apiext.h> |
---|
| 33 | #include <rtems/score/sysstate.h> |
---|
| 34 | |
---|
| 35 | /*PAGE |
---|
| 36 | * |
---|
| 37 | * rtems_task_mode |
---|
| 38 | * |
---|
| 39 | * This directive enables and disables several modes of |
---|
| 40 | * execution for the requesting thread. |
---|
| 41 | * |
---|
| 42 | * Input parameters: |
---|
| 43 | * mode_set - new mode |
---|
| 44 | * mask - mask |
---|
| 45 | * previous_mode_set - address of previous mode set |
---|
| 46 | * |
---|
| 47 | * Output: |
---|
| 48 | * *previous_mode_set - previous mode set |
---|
| 49 | * always return RTEMS_SUCCESSFUL; |
---|
| 50 | */ |
---|
| 51 | |
---|
| 52 | rtems_status_code rtems_task_mode( |
---|
| 53 | rtems_mode mode_set, |
---|
| 54 | rtems_mode mask, |
---|
| 55 | rtems_mode *previous_mode_set |
---|
| 56 | ) |
---|
| 57 | { |
---|
| 58 | Thread_Control *executing; |
---|
| 59 | RTEMS_API_Control *api; |
---|
| 60 | ASR_Information *asr; |
---|
| 61 | boolean is_asr_enabled = FALSE; |
---|
| 62 | boolean needs_asr_dispatching = FALSE; |
---|
| 63 | rtems_mode old_mode; |
---|
| 64 | |
---|
[e980b219] | 65 | if ( !previous_mode_set ) |
---|
| 66 | return RTEMS_INVALID_ADDRESS; |
---|
| 67 | |
---|
[c4d69e2] | 68 | executing = _Thread_Executing; |
---|
| 69 | api = executing->API_Extensions[ THREAD_API_RTEMS ]; |
---|
| 70 | asr = &api->Signal; |
---|
| 71 | |
---|
| 72 | old_mode = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT; |
---|
| 73 | |
---|
| 74 | if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE ) |
---|
| 75 | old_mode |= RTEMS_NO_TIMESLICE; |
---|
| 76 | else |
---|
| 77 | old_mode |= RTEMS_TIMESLICE; |
---|
| 78 | |
---|
| 79 | old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR; |
---|
| 80 | old_mode |= _ISR_Get_level(); |
---|
| 81 | |
---|
| 82 | *previous_mode_set = old_mode; |
---|
| 83 | |
---|
| 84 | /* |
---|
| 85 | * These are generic thread scheduling characteristics. |
---|
| 86 | */ |
---|
| 87 | |
---|
| 88 | if ( mask & RTEMS_PREEMPT_MASK ) |
---|
| 89 | executing->is_preemptible = _Modes_Is_preempt(mode_set) ? TRUE : FALSE; |
---|
| 90 | |
---|
| 91 | if ( mask & RTEMS_TIMESLICE_MASK ) { |
---|
[c0f4682] | 92 | if ( _Modes_Is_timeslice(mode_set) ) { |
---|
[c4d69e2] | 93 | executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE; |
---|
[c0f4682] | 94 | executing->cpu_time_budget = _Thread_Ticks_per_timeslice; |
---|
| 95 | } else |
---|
[c4d69e2] | 96 | executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE; |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | /* |
---|
| 100 | * Set the new interrupt level |
---|
| 101 | */ |
---|
| 102 | |
---|
| 103 | if ( mask & RTEMS_INTERRUPT_MASK ) |
---|
| 104 | _Modes_Set_interrupt_level( mode_set ); |
---|
| 105 | |
---|
| 106 | /* |
---|
| 107 | * This is specific to the RTEMS API |
---|
| 108 | */ |
---|
| 109 | |
---|
| 110 | is_asr_enabled = FALSE; |
---|
| 111 | needs_asr_dispatching = FALSE; |
---|
| 112 | |
---|
| 113 | if ( mask & RTEMS_ASR_MASK ) { |
---|
| 114 | is_asr_enabled = _Modes_Is_asr_disabled( mode_set ) ? FALSE : TRUE; |
---|
| 115 | if ( is_asr_enabled != asr->is_enabled ) { |
---|
| 116 | asr->is_enabled = is_asr_enabled; |
---|
| 117 | _ASR_Swap_signals( asr ); |
---|
| 118 | if ( _ASR_Are_signals_pending( asr ) ) { |
---|
| 119 | needs_asr_dispatching = TRUE; |
---|
| 120 | executing->do_post_task_switch_extension = TRUE; |
---|
| 121 | } |
---|
| 122 | } |
---|
| 123 | } |
---|
| 124 | |
---|
[3afb0d2] | 125 | if ( _System_state_Is_up(_System_state_Current) ) |
---|
| 126 | if ( _Thread_Evaluate_mode() || needs_asr_dispatching ) |
---|
| 127 | _Thread_Dispatch(); |
---|
[c4d69e2] | 128 | |
---|
| 129 | return RTEMS_SUCCESSFUL; |
---|
| 130 | } |
---|