source: rtems/cpukit/rtems/src/taskmode.c @ a7a9e193

4.8
Last change on this file since a7a9e193 was c25cea9, checked in by Joel Sherrill <joel.sherrill@…>, on 08/05/08 at 13:11:01

2008-08-05 Xudong Guan <xudong.guan@…>

PR 1212/cpukit

  • rtems/src/taskmode.c, score/src/threadtickletimeslice.c: Time slicing will not happen if the task mode is changed from a non-timeslicing mode to timeslicing mode if it is done by the executing thread (e.g. in its task body). This change includes sp44 to demonstrate the problem and verify the correction.
  • Property mode set to 100644
File size: 3.3 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.rtems.com/license/LICENSE.
11 *
12 *  $Id$
13 */
14
15#if HAVE_CONFIG_H
16#include "config.h"
17#endif
18
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
52rtems_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
65  if ( !previous_mode_set )
66    return RTEMS_INVALID_ADDRESS;
67
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 ) {
92    if ( _Modes_Is_timeslice(mode_set) ) {
93      executing->budget_algorithm = THREAD_CPU_BUDGET_ALGORITHM_RESET_TIMESLICE;
94      executing->cpu_time_budget  = _Thread_Ticks_per_timeslice;
95    } else
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
125  if ( _System_state_Is_up(_System_state_Current) )
126    if ( _Thread_Evaluate_mode() || needs_asr_dispatching )
127      _Thread_Dispatch();
128
129  return RTEMS_SUCCESSFUL;
130}
Note: See TracBrowser for help on using the repository browser.