1 #ifndef CYGONCE_KERNEL_SCHED_INL
2 #define CYGONCE_KERNEL_SCHED_INL
4 //==========================================================================
8 // Scheduler class inlines
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.
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.
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
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.
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.
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.
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####
47 // Contributors: nickg
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.
54 // #include <cyg/kernel/sched.hxx>
56 // #include <cyg/kernel/sched.inl>
59 //####DESCRIPTIONEND####
61 //==========================================================================
63 #include <cyg/kernel/instrmnt.h>
64 #include <cyg/hal/hal_arch.h>
66 // -------------------------------------------------------------------------
67 // Inlines for Cyg_Scheduler class
69 inline void Cyg_Scheduler::lock()
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.
76 HAL_REORDER_BARRIER();
80 HAL_REORDER_BARRIER();
82 CYG_INSTRUMENT_SCHED(LOCK,get_sched_lock(),0);
85 inline void Cyg_Scheduler::unlock()
87 // This is an inline wrapper for the real scheduler unlock function in
88 // Cyg_Scheduler::unlock_inner().
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.
94 CYG_INSTRUMENT_SCHED(UNLOCK,get_sched_lock(),0);
96 HAL_REORDER_BARRIER();
98 cyg_ucount32 __lock = get_sched_lock() - 1;
100 if( __lock == 0 ) unlock_inner(0);
101 else set_sched_lock(__lock);
103 HAL_REORDER_BARRIER();
106 inline void Cyg_Scheduler::reschedule()
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.
113 CYG_INSTRUMENT_SCHED(RESCHEDULE,get_sched_lock(),0);
115 unlock_inner( get_sched_lock() );
118 inline void Cyg_Scheduler:: unlock_reschedule()
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().
126 CYG_INSTRUMENT_SCHED(UNLOCK,get_sched_lock(),0);
128 unlock_inner( get_sched_lock() - 1 );
131 inline void Cyg_Scheduler::unlock_simple()
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.
139 CYG_INSTRUMENT_SCHED(UNLOCK,get_sched_lock(),0);
141 HAL_REORDER_BARRIER();
143 if (get_sched_lock() > 1)
144 set_sched_lock(get_sched_lock() - 1);
145 else zero_sched_lock();
147 HAL_REORDER_BARRIER();
151 // -------------------------------------------------------------------------
152 // Inlines for Cyg_SchedThread class
154 #include <cyg/kernel/thread.inl> // we use some thread inlines here
156 inline void Cyg_SchedThread::remove()
160 queue->remove((Cyg_Thread *)this);
165 // -------------------------------------------------------------------------
167 #endif // ifndef CYGONCE_KERNEL_SCHED_INL