source: rtems/cpukit/score/src/threaddispatchdisablelevel.c @ dad36c52

4.115
Last change on this file since dad36c52 was dad36c52, checked in by Jennifer Averett <Jennifer.Averett@…>, on 08/22/11 at 18:26:08

2011-08-22 Jennifer Averett <Jennifer.Averett@…>

PR 1876

  • score/Makefile.am, score/include/rtems/score/isr.h, score/src/isr.c, score/src/smp.c, score/src/smplock.c, score/src/threaddispatch.c, score/src/threaddispatchdisablelevel.c: Add smp isr support.
  • score/src/isrsmp.c: New file.
  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  Thread Dispatch Disable Level Methods
3 *
4 *  COPYRIGHT (c) 1989-2011.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#include <rtems/system.h>
15#include <rtems/score/apiext.h>
16#include <rtems/score/context.h>
17#include <rtems/score/interr.h>
18#include <rtems/score/isr.h>
19#include <rtems/score/object.h>
20#include <rtems/score/priority.h>
21#include <rtems/score/states.h>
22#include <rtems/score/sysstate.h>
23#include <rtems/score/thread.h>
24
25void _Thread_Dispatch_initialization( void )
26{
27  _Thread_Dispatch_disable_level = 0;
28  _SMP_lock_spinlock_nested_Initialize(&_Thread_Dispatch_disable_level_lock);
29  _Thread_Dispatch_set_disable_level( 1 );
30}
31
32bool _Thread_Dispatch_in_critical_section(void)
33{
34  if (  _Thread_Dispatch_disable_level == 0 )
35   return false;
36
37  return true;
38}
39
40uint32_t _Thread_Dispatch_get_disable_level(void)
41{
42  return _Thread_Dispatch_disable_level;
43}
44
45uint32_t _Thread_Dispatch_increment_disable_level(void)
46{
47  ISR_Level  isr_level;
48  uint32_t   level;
49
50  /*
51   * Note: _SMP_lock_spinlock_nested_Obtain returns
52   *       with ISR's disabled and the isr_level that
53   *       should be restored after a short period.
54   *
55   * Here we obtain the lock and increment the
56   * Thread dispatch disable level while under the
57   * protection of the isr being off.  After this
58   * point it is safe to re-enable ISRs and allow
59   * the dispatch disable lock to provide protection.
60   */
61
62  isr_level = _SMP_lock_spinlock_nested_Obtain(
63    &_Thread_Dispatch_disable_level_lock
64  );
65 
66  _Thread_Dispatch_disable_level++;
67  level = _Thread_Dispatch_disable_level;
68
69  _ISR_Enable_on_this_core(isr_level);
70  return level;
71}
72
73uint32_t _Thread_Dispatch_decrement_disable_level(void)
74{
75  ISR_Level  isr_level;
76  uint32_t   level;
77
78  /*  First we must disable ISRs in order to protect
79   *  accesses to the dispatch disable level.
80   */
81  _ISR_Disable_on_this_core( isr_level );
82
83  _Thread_Dispatch_disable_level--;
84  level = _Thread_Dispatch_disable_level;
85
86
87  /*
88   * Note: _SMP_lock_spinlock_nested_Obtain returns with
89   *        ISR's disabled and _SMP_lock_spinlock_nested_Release
90   *        is responsable for re-enabling interrupts.
91   */
92  _SMP_lock_spinlock_nested_Release(
93    &_Thread_Dispatch_disable_level_lock,
94    isr_level
95  );
96
97  return level;
98}
99
100
101/*
102 * Note this method is taking a heavy handed approach to
103 * setting the dispatch level. This may be optimized at a
104 * later timee, but it must be in such a way that the nesting
105 * level is decremented by the same number as the dispatch level.
106 * This approach is safest until we are sure the nested spinlock
107 * is successfully working with smp isr source code. 
108 */
109
110uint32_t _Thread_Dispatch_set_disable_level(uint32_t value)
111{
112  /*
113   * If we need the dispatch level to go higher
114   * call increment method the desired number of times.
115   */
116
117  while ( value > _Thread_Dispatch_disable_level ) {
118    _Thread_Dispatch_increment_disable_level();
119  }
120
121  /*
122   * If we need the dispatch level to go lower
123   * call increment method the desired number of times.
124   */
125
126  while ( value < _Thread_Dispatch_disable_level ) {
127    _Thread_Dispatch_decrement_disable_level();
128  }
129
130  return value;
131}
Note: See TracBrowser for help on using the repository browser.