source: rtems/cpukit/rtems/src/taskmode.c @ 39046f7

4.115
Last change on this file since 39046f7 was 39046f7, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 09:09:23

score: Merge sysstate API into one file

  • Property mode set to 100644
File size: 2.9 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief RTEMS Task Mode
5 *  @ingroup ClassicTasks
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2010.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/config.h>
23#include <rtems/rtems/asrimpl.h>
24#include <rtems/rtems/status.h>
25#include <rtems/rtems/support.h>
26#include <rtems/rtems/modesimpl.h>
27#include <rtems/score/object.h>
28#include <rtems/score/stack.h>
29#include <rtems/score/states.h>
30#include <rtems/rtems/tasksimpl.h>
31#include <rtems/score/thread.h>
32#include <rtems/score/threadq.h>
33#include <rtems/score/tod.h>
34#include <rtems/score/wkspace.h>
35#include <rtems/score/apiext.h>
36
37rtems_status_code rtems_task_mode(
38  rtems_mode  mode_set,
39  rtems_mode  mask,
40  rtems_mode *previous_mode_set
41)
42{
43  Thread_Control     *executing;
44  RTEMS_API_Control  *api;
45  ASR_Information    *asr;
46  bool                needs_asr_dispatching;
47  rtems_mode          old_mode;
48
49  if ( !previous_mode_set )
50    return RTEMS_INVALID_ADDRESS;
51
52  executing     = _Thread_Get_executing();
53  api = executing->API_Extensions[ THREAD_API_RTEMS ];
54  asr = &api->Signal;
55
56  old_mode  = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT;
57
58  if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE )
59    old_mode |= RTEMS_NO_TIMESLICE;
60  else
61    old_mode |= RTEMS_TIMESLICE;
62
63  old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR;
64  old_mode |= _ISR_Get_level();
65
66  *previous_mode_set = old_mode;
67
68  /*
69   *  These are generic thread scheduling characteristics.
70   */
71  if ( mask & RTEMS_PREEMPT_MASK ) {
72#if defined( RTEMS_SMP )
73    if (
74      rtems_configuration_is_smp_enabled()
75        && !_Modes_Is_preempt( mode_set )
76    ) {
77      return RTEMS_NOT_IMPLEMENTED;
78    }
79#endif
80
81    executing->is_preemptible = _Modes_Is_preempt( mode_set );
82  }
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      executing->cpu_time_budget  = _Thread_Ticks_per_timeslice;
88    } else
89      executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
90  }
91
92  /*
93   *  Set the new interrupt level
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  needs_asr_dispatching = false;
102  if ( mask & RTEMS_ASR_MASK ) {
103    bool is_asr_enabled = !_Modes_Is_asr_disabled( mode_set );
104
105    if ( is_asr_enabled != asr->is_enabled ) {
106      asr->is_enabled = is_asr_enabled;
107      _ASR_Swap_signals( asr );
108      if ( _ASR_Are_signals_pending( asr ) ) {
109        needs_asr_dispatching = true;
110      }
111    }
112  }
113
114  _Thread_Dispatch_if_necessary( executing, needs_asr_dispatching );
115
116  return RTEMS_SUCCESSFUL;
117}
Note: See TracBrowser for help on using the repository browser.