Mercurial > flash_v2
annotate packages/kernel/current/include/sched.hxx @ 62:7a6ac9edc838 ecos-sw-2000-01-24
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
| author | jlarmour |
|---|---|
| date | Mon, 24 Jan 2000 21:43:17 +0000 |
| parents | 443894e2e912 |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_SCHED_HXX |
| 2 #define CYGONCE_KERNEL_SCHED_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // sched.hxx |
| 0 | 7 // |
| 2 | 8 // Scheduler class declaration(s) |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
| 12 // | |
| 13 // ------------------------------------------- | |
| 14 // The contents of this file are subject to the Cygnus eCos Public License | |
| 15 // Version 1.0 (the "License"); you may not use this file except in | |
| 16 // compliance with the License. You may obtain a copy of the License at | |
| 17 // http://sourceware.cygnus.com/ecos | |
| 18 // | |
| 19 // Software distributed under the License is distributed on an "AS IS" | |
| 20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 21 // License for the specific language governing rights and limitations under | |
| 22 // the License. | |
| 23 // | |
| 24 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 25 // September 30, 1998. | |
| 26 // | |
| 27 // The Initial Developer of the Original Code is Cygnus. Portions created | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
28 // by Cygnus are Copyright (C) 1998,1999,2000 Cygnus Solutions. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
29 // All Rights Reserved. |
| 0 | 30 // ------------------------------------------- |
| 31 // | |
| 32 //####COPYRIGHTEND#### | |
| 33 //========================================================================== | |
| 34 //#####DESCRIPTIONBEGIN#### | |
| 35 // | |
| 2 | 36 // Author(s): nickg |
| 37 // Contributors: nickg | |
| 38 // Date: 1997-09-09 | |
| 39 // Purpose: Define Scheduler class interfaces | |
| 40 // Description: These class definitions supply the internal API | |
| 0 | 41 // used to scheduler threads. |
| 2 | 42 // Usage: #include <cyg/kernel/sched.hxx> |
| 0 | 43 // |
| 44 //####DESCRIPTIONEND#### | |
| 45 // | |
| 46 //========================================================================== | |
| 47 | |
| 48 #include <cyg/kernel/ktypes.h> | |
| 49 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 50 | |
| 51 // ------------------------------------------------------------------------- | |
| 52 // Scheduler base class. This defines stuff that is needed by the | |
| 53 // specific scheduler implementation. Each scheduler comprises three | |
| 54 // classes: Cyg_Scheduler_Base, Cyg_Scheduler_Implementation which | |
| 55 // inherits from it and Cyg_Scheduler which inherits from _it_ in turn. | |
| 56 | |
| 57 class Cyg_Scheduler_Base | |
| 58 { | |
| 59 friend class Cyg_HardwareThread; | |
| 60 friend class Cyg_SchedThread; | |
| 61 | |
| 62 protected: | |
| 63 // The following variables are implicit in the API, but are | |
| 64 // not publically visible. | |
| 65 | |
| 2 | 66 static volatile cyg_ucount32 sched_lock // lock counter |
| 67 CYGBLD_ATTRIB_ASM_ALIAS( cyg_scheduler_sched_lock ); | |
| 68 | |
| 0 | 69 static Cyg_Thread *current_thread; // current running thread |
| 70 | |
| 71 static cyg_bool need_reschedule; // set when schedule needed | |
| 72 | |
| 73 static cyg_ucount32 thread_switches; // count of number of thread switches | |
| 74 }; | |
| 75 | |
| 76 // ------------------------------------------------------------------------- | |
| 77 // Include the scheduler implementation header | |
| 78 | |
| 79 #include CYGPRI_KERNEL_SCHED_IMPL_HXX | |
| 80 | |
| 81 // Do some checking that we have a consistent universe. | |
| 82 | |
| 83 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | |
| 84 # ifndef CYGIMP_THREAD_PRIORITY | |
| 85 # error Priority inheritance will not work without priorities!!! | |
| 86 # endif | |
| 87 # if CYG_SCHED_UNIQUE_PRIORITIES | |
| 88 # error Priority inheritance needs non-unique priorities!!! | |
| 89 # endif | |
| 90 #endif | |
| 91 | |
| 92 // ------------------------------------------------------------------------- | |
| 93 // Scheduler class. This is the public scheduler interface seen by the | |
| 94 // rest of the kernel. | |
| 95 | |
| 96 class Cyg_Scheduler | |
| 97 : public Cyg_Scheduler_Implementation | |
| 98 { | |
| 99 friend class Cyg_Thread; | |
| 100 | |
| 101 // This function is the actual implementation of the unlock | |
| 102 // function. The unlock() later is an inline shell that deals | |
| 103 // with the common case. | |
| 104 | |
| 105 static void unlock_inner(); | |
| 106 | |
| 107 public: | |
| 108 | |
| 109 CYGDBG_DEFINE_CHECK_THIS | |
| 110 | |
| 111 // The following API functions are common to all scheduler | |
| 112 // implementations. | |
| 113 | |
| 114 // claim the preemption lock | |
| 115 static void lock(); | |
| 116 | |
| 2 | 117 // release the preemption lock and possibly reschedule |
| 0 | 118 static void unlock(); |
| 119 | |
| 2 | 120 // release the preemption lock without rescheduling |
| 121 static void unlock_simple(); | |
| 122 | |
| 0 | 123 // return a pointer to the current thread |
| 124 static Cyg_Thread *get_current_thread(); | |
| 125 | |
| 126 // Return current value of lock | |
| 127 static cyg_ucount32 get_sched_lock(); | |
| 128 | |
| 129 // Return current number of thread switches | |
| 130 static cyg_ucount32 get_thread_switches(); | |
| 131 | |
| 132 // Start execution of the scheduler | |
| 133 static void start() __attribute__ ((noreturn)); | |
| 134 | |
| 135 // The only scheduler instance should be this one... | |
| 136 static Cyg_Scheduler scheduler; | |
| 137 | |
| 138 }; | |
| 139 | |
| 140 // ------------------------------------------------------------------------- | |
| 141 // This class encapsulates the scheduling abstractions in a thread. | |
| 142 // Cyg_SchedThread is included as a base class of Cyg_Thread. The actual | |
| 143 // implementation of the abstractions is in Cyg_SchedThread_Implementation | |
| 144 // so this class has little to do. | |
| 145 | |
| 146 class Cyg_SchedThread | |
| 147 : public Cyg_SchedThread_Implementation | |
| 148 { | |
| 149 friend class Cyg_ThreadQueue_Implementation; | |
| 150 friend class Cyg_Scheduler_Implementation; | |
| 151 | |
| 152 Cyg_ThreadQueue *queue; | |
| 153 | |
| 154 | |
| 155 public: | |
| 156 | |
| 157 Cyg_SchedThread(Cyg_Thread *thread, CYG_ADDRWORD sched_info); | |
| 158 | |
| 159 // Return current queue pointer | |
| 160 | |
| 161 Cyg_ThreadQueue *get_current_queue(); | |
| 162 | |
| 163 // Remove this thread from current queue | |
| 164 void remove(); | |
| 165 | |
| 166 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | |
| 167 | |
| 168 private: | |
| 169 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
170 // For all priority inheritance mechanisms we need to keep track of how |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
171 // many mutexes we have locked, including one which we are waiting to |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
172 // lock, because we can inherit priority while sleeping just prior to |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
173 // wakeup. |
| 0 | 174 cyg_count32 mutex_count; |
| 175 | |
| 176 public: | |
| 177 // Count and uncount the number of mutexes held by | |
| 178 // this thread. | |
| 179 void count_mutex() { mutex_count++; }; | |
| 180 void uncount_mutex() { mutex_count--; }; | |
| 181 | |
| 182 protected: | |
| 183 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 184 | |
| 185 // The simple priority inheritance mechanism simply needs | |
| 186 // somewhere to store the base priority of the current thread. | |
| 187 | |
| 188 cyg_priority original_priority; // our original priority | |
| 189 | |
| 190 cyg_bool priority_inherited; // have we inherited? | |
| 191 | |
| 192 #endif | |
| 193 | |
| 194 public: | |
| 195 | |
| 196 // Inherit the priority of the provided thread if it | |
| 197 // has higher priority than this. | |
| 198 void inherit_priority( Cyg_Thread *thread); | |
| 199 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
200 // Relay the priority of the ex-owner thread or from the queue if it |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
201 // has a higher priority than ours. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
202 void relay_priority( Cyg_Thread *ex_owner, Cyg_ThreadQueue *pqueue); |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
203 |
| 0 | 204 // Lose priority inheritance |
| 205 void disinherit_priority(); | |
| 206 | |
| 207 #endif | |
| 208 | |
| 209 }; | |
| 210 | |
| 211 // ------------------------------------------------------------------------- | |
| 212 // Simple inline accessor functions | |
| 213 | |
| 214 inline Cyg_Thread *Cyg_Scheduler::get_current_thread() | |
| 215 { | |
| 216 return current_thread; | |
| 217 } | |
| 218 | |
| 219 // Return current value of lock | |
| 220 inline cyg_ucount32 Cyg_Scheduler::get_sched_lock() | |
| 221 { | |
| 222 return sched_lock; | |
| 223 } | |
| 224 | |
| 225 // Return current number of thread switches | |
| 226 inline cyg_ucount32 Cyg_Scheduler::get_thread_switches() | |
| 227 { | |
| 228 return thread_switches; | |
| 229 } | |
| 230 | |
| 231 // Return current queue pointer | |
| 232 inline Cyg_ThreadQueue *Cyg_SchedThread::get_current_queue() | |
| 233 { | |
| 234 return queue; | |
| 235 } | |
| 236 | |
| 237 // ------------------------------------------------------------------------- | |
| 238 #endif // ifndef __SCHED_HXX__ | |
| 239 // EOF sched.hxx |
