source: rtems/cpukit/rtems/src/taskmode.c @ 4bf1801

4.104.114.84.95
Last change on this file since 4bf1801 was 08311cc3, checked in by Joel Sherrill <joel.sherrill@…>, on 11/17/99 at 17:51:34

Updated copyright notice.

  • Property mode set to 100644
File size: 3.1 KB
Line 
1/*
2 *  RTEMS Task Manager
3 *
4 *
5 *  COPYRIGHT (c) 1989-1999.
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
10 *  http://www.OARcorp.com/rtems/license.html.
11 *
12 *  $Id$
13 */
14
15#include <rtems/system.h>
16#include <rtems/rtems/status.h>
17#include <rtems/rtems/support.h>
18#include <rtems/rtems/modes.h>
19#include <rtems/score/object.h>
20#include <rtems/score/stack.h>
21#include <rtems/score/states.h>
22#include <rtems/rtems/tasks.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/threadq.h>
25#include <rtems/score/tod.h>
26#include <rtems/score/userext.h>
27#include <rtems/score/wkspace.h>
28#include <rtems/score/apiext.h>
29#include <rtems/score/sysstate.h>
30
31/*PAGE
32 *
33 *  rtems_task_mode
34 *
35 *  This directive enables and disables several modes of
36 *  execution for the requesting thread.
37 *
38 *  Input parameters:
39 *    mode_set          - new mode
40 *    mask              - mask
41 *    previous_mode_set - address of previous mode set
42 *
43 *  Output:
44 *    *previous_mode_set - previous mode set
45 *     always return RTEMS_SUCCESSFUL;
46 */
47
48rtems_status_code rtems_task_mode(
49  rtems_mode  mode_set,
50  rtems_mode  mask,
51  rtems_mode *previous_mode_set
52)
53{
54  Thread_Control     *executing;
55  RTEMS_API_Control  *api;
56  ASR_Information    *asr;
57  boolean             is_asr_enabled = FALSE;
58  boolean             needs_asr_dispatching = FALSE;
59  rtems_mode          old_mode;
60
61  executing     = _Thread_Executing;
62  api = executing->API_Extensions[ THREAD_API_RTEMS ];
63  asr = &api->Signal;
64
65  old_mode  = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT;
66
67  if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE )
68    old_mode |= RTEMS_NO_TIMESLICE;
69  else
70    old_mode |= RTEMS_TIMESLICE;
71
72  old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR;
73  old_mode |= _ISR_Get_level();
74
75  *previous_mode_set = old_mode;
76
77  /*
78   *  These are generic thread scheduling characteristics.
79   */
80
81  if ( mask & RTEMS_PREEMPT_MASK )
82    executing->is_preemptible = _Modes_Is_preempt(mode_set) ? TRUE : FALSE;
83
84  if ( mask & RTEMS_TIMESLICE_MASK ) {
85    if ( _Modes_Is_timeslice(mode_set) )
86      executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
87    else
88      executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
89  }
90
91  /*
92   *  Set the new interrupt level
93   */
94
95  if ( mask & RTEMS_INTERRUPT_MASK )
96    _Modes_Set_interrupt_level( mode_set );
97
98  /*
99   *  This is specific to the RTEMS API
100   */
101
102  is_asr_enabled = FALSE;
103  needs_asr_dispatching = FALSE;
104
105  if ( mask & RTEMS_ASR_MASK ) {
106    is_asr_enabled = _Modes_Is_asr_disabled( mode_set ) ? FALSE : TRUE;
107    if ( is_asr_enabled != asr->is_enabled ) {
108      asr->is_enabled = is_asr_enabled;
109      _ASR_Swap_signals( asr );
110      if ( _ASR_Are_signals_pending( asr ) ) {
111        needs_asr_dispatching = TRUE;
112        executing->do_post_task_switch_extension = TRUE;
113      }
114    }
115  }
116
117  if ( _Thread_Evaluate_mode() || needs_asr_dispatching )
118    _Thread_Dispatch();
119
120  return RTEMS_SUCCESSFUL;
121}
Note: See TracBrowser for help on using the repository browser.