]> git.kernelconcepts.de Git - karo-tx-redboot.git/blob - packages/kernel/v2_0/include/sched.inl
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / kernel / v2_0 / include / sched.inl
1 #ifndef CYGONCE_KERNEL_SCHED_INL
2 #define CYGONCE_KERNEL_SCHED_INL
3
4 //==========================================================================
5 //
6 //      sched.inl
7 //
8 //      Scheduler class inlines
9 //
10 //==========================================================================
11 //####ECOSGPLCOPYRIGHTBEGIN####
12 // -------------------------------------------
13 // This file is part of eCos, the Embedded Configurable Operating System.
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
15 //
16 // eCos is free software; you can redistribute it and/or modify it under
17 // the terms of the GNU General Public License as published by the Free
18 // Software Foundation; either version 2 or (at your option) any later version.
19 //
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
22 // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23 // for more details.
24 //
25 // You should have received a copy of the GNU General Public License along
26 // with eCos; if not, write to the Free Software Foundation, Inc.,
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 //
29 // As a special exception, if other files instantiate templates or use macros
30 // or inline functions from this file, or you compile this file and link it
31 // with other works to produce a work based on this file, this file does not
32 // by itself cause the resulting work to be covered by the GNU General Public
33 // License. However the source code for this file must still be made available
34 // in accordance with section (3) of the GNU General Public License.
35 //
36 // This exception does not invalidate any other reasons why a work based on
37 // this file might be covered by the GNU General Public License.
38 //
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
40 // at http://sources.redhat.com/ecos/ecos-license/
41 // -------------------------------------------
42 //####ECOSGPLCOPYRIGHTEND####
43 //==========================================================================
44 //#####DESCRIPTIONBEGIN####
45 //
46 // Author(s):   nickg
47 // Contributors:        nickg
48 // Date:        1997-09-09
49 // Purpose:     Define inlines for scheduler classes
50 // Description: Inline functions for the scheduler classes. These are
51 //              not defined in the header so that we have the option
52 //              of making them non-inline.
53 // Usage:
54 //              #include <cyg/kernel/sched.hxx>
55 //              ...
56 //              #include <cyg/kernel/sched.inl>
57 //              ...
58 //
59 //####DESCRIPTIONEND####
60 //
61 //==========================================================================
62
63 #include <cyg/kernel/instrmnt.h>
64 #include <cyg/hal/hal_arch.h>
65
66 // -------------------------------------------------------------------------
67 // Inlines for Cyg_Scheduler class
68
69 inline void Cyg_Scheduler::lock()
70 {
71     // We do not need to do a read-modify-write sequence here because
72     // the scheduler lock is strictly nesting. Even if we are interrupted
73     // partway through the increment, the lock will be returned to the same
74     // value before we are resumed/rescheduled.
75
76     HAL_REORDER_BARRIER();
77
78     inc_sched_lock();
79
80     HAL_REORDER_BARRIER();
81
82     CYG_INSTRUMENT_SCHED(LOCK,get_sched_lock(),0);
83 };
84
85 inline void Cyg_Scheduler::unlock()
86 {
87     // This is an inline wrapper for the real scheduler unlock function in
88     // Cyg_Scheduler::unlock_inner().
89     
90     // Only do anything if the lock is about to go zero, otherwise we simply
91     // decrement and return. As with lock() we do not need any special code
92     // to decrement the lock counter.
93
94     CYG_INSTRUMENT_SCHED(UNLOCK,get_sched_lock(),0);
95     
96     HAL_REORDER_BARRIER();
97     
98     cyg_ucount32 __lock = get_sched_lock() - 1;
99     
100     if( __lock == 0 ) unlock_inner(0);
101     else set_sched_lock(__lock);
102
103     HAL_REORDER_BARRIER();
104 }
105
106 inline void Cyg_Scheduler::reschedule()
107 {
108     // This function performs the equivalent of calling unlock() and
109     // lock() is succession. Unlike that pair, however, it does not
110     // leave a brief window between the calls when the lock is unclaimed
111     // by the current thread.
112     
113     CYG_INSTRUMENT_SCHED(RESCHEDULE,get_sched_lock(),0);
114     
115     unlock_inner( get_sched_lock() );
116 }
117
118 inline void Cyg_Scheduler:: unlock_reschedule()
119 {
120     // This function decrements the scheduler lock and also looks for
121     // a reschedule opportunity. When the lock is being decremented
122     // from 1 to zero this function is equivalent to unlock. When the
123     // lock is being decremented to a non-zero value, it is more or less
124     // equivalent to reschedule() followed by unlock().
125     
126     CYG_INSTRUMENT_SCHED(UNLOCK,get_sched_lock(),0);
127     
128     unlock_inner( get_sched_lock() - 1 );
129 }
130
131 inline void Cyg_Scheduler::unlock_simple()
132 {
133     // This function decrements the lock, but does not call unlock_inner().
134     // Therefore does not immediately allow another thread to run:
135     // merely makes it possible for some other thread to run at some
136     // indeterminate future time.  This is mainly for use by
137     // debuggers, it should not normally be used anywhere else.
138
139     CYG_INSTRUMENT_SCHED(UNLOCK,get_sched_lock(),0);
140
141     HAL_REORDER_BARRIER();
142         
143     if (get_sched_lock() > 1)
144         set_sched_lock(get_sched_lock() - 1);
145     else zero_sched_lock();
146
147     HAL_REORDER_BARRIER();
148 }
149
150
151 // -------------------------------------------------------------------------
152 // Inlines for Cyg_SchedThread class
153
154 #include <cyg/kernel/thread.inl>   // we use some thread inlines here
155
156 inline void Cyg_SchedThread::remove()
157 {
158     if( queue != NULL )
159     {
160         queue->remove((Cyg_Thread *)this);
161         queue = NULL;
162     }
163 }
164
165 // -------------------------------------------------------------------------
166
167 #endif // ifndef CYGONCE_KERNEL_SCHED_INL
168 // EOF sched.inl