source: rtems/cpukit/score/src/threaddispatchdisablelevel.c @ 2d7ae960

4.115
Last change on this file since 2d7ae960 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

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