source: rtems/cpukit/rtems/src/taskmode.c @ 5618c37a

4.115
Last change on this file since 5618c37a was 5618c37a, checked in by Sebastian Huber <sebastian.huber@…>, on 07/24/13 at 13:14:48

score: Create thread implementation header

Move implementation specific parts of thread.h and thread.inl into new
header file threadimpl.h. The thread.h contains now only the
application visible API.

Remove superfluous header file includes from various files.

  • Property mode set to 100644
File size: 2.6 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/rtems/tasks.h>
22#include <rtems/rtems/asrimpl.h>
23#include <rtems/rtems/modesimpl.h>
24#include <rtems/score/threadimpl.h>
25#include <rtems/config.h>
26
27rtems_status_code rtems_task_mode(
28  rtems_mode  mode_set,
29  rtems_mode  mask,
30  rtems_mode *previous_mode_set
31)
32{
33  Thread_Control     *executing;
34  RTEMS_API_Control  *api;
35  ASR_Information    *asr;
36  bool                needs_asr_dispatching;
37  rtems_mode          old_mode;
38
39  if ( !previous_mode_set )
40    return RTEMS_INVALID_ADDRESS;
41
42  executing     = _Thread_Get_executing();
43  api = executing->API_Extensions[ THREAD_API_RTEMS ];
44  asr = &api->Signal;
45
46  old_mode  = (executing->is_preemptible) ? RTEMS_PREEMPT : RTEMS_NO_PREEMPT;
47
48  if ( executing->budget_algorithm == THREAD_CPU_BUDGET_ALGORITHM_NONE )
49    old_mode |= RTEMS_NO_TIMESLICE;
50  else
51    old_mode |= RTEMS_TIMESLICE;
52
53  old_mode |= (asr->is_enabled) ? RTEMS_ASR : RTEMS_NO_ASR;
54  old_mode |= _ISR_Get_level();
55
56  *previous_mode_set = old_mode;
57
58  /*
59   *  These are generic thread scheduling characteristics.
60   */
61  if ( mask & RTEMS_PREEMPT_MASK ) {
62#if defined( RTEMS_SMP )
63    if (
64      rtems_configuration_is_smp_enabled()
65        && !_Modes_Is_preempt( mode_set )
66    ) {
67      return RTEMS_NOT_IMPLEMENTED;
68    }
69#endif
70
71    executing->is_preemptible = _Modes_Is_preempt( mode_set );
72  }
73
74  if ( mask & RTEMS_TIMESLICE_MASK ) {
75    if ( _Modes_Is_timeslice(mode_set) ) {
76      executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
77      executing->cpu_time_budget  = _Thread_Ticks_per_timeslice;
78    } else
79      executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_NONE;
80  }
81
82  /*
83   *  Set the new interrupt level
84   */
85  if ( mask & RTEMS_INTERRUPT_MASK )
86    _Modes_Set_interrupt_level( mode_set );
87
88  /*
89   *  This is specific to the RTEMS API
90   */
91  needs_asr_dispatching = false;
92  if ( mask & RTEMS_ASR_MASK ) {
93    bool is_asr_enabled = !_Modes_Is_asr_disabled( mode_set );
94
95    if ( is_asr_enabled != asr->is_enabled ) {
96      asr->is_enabled = is_asr_enabled;
97      _ASR_Swap_signals( asr );
98      if ( _ASR_Are_signals_pending( asr ) ) {
99        needs_asr_dispatching = true;
100      }
101    }
102  }
103
104  _Thread_Dispatch_if_necessary( executing, needs_asr_dispatching );
105
106  return RTEMS_SUCCESSFUL;
107}
Note: See TracBrowser for help on using the repository browser.