Mercurial > flash_v2
annotate packages/kernel/current/src/sched/sched.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | 59d97b6ba612 |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 2 | 3 // sched/sched.cxx |
| 0 | 4 // |
| 2 | 5 // Scheduler class implementations |
| 0 | 6 // |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): nickg |
| 35 // Contributors: nickg | |
| 36 // Date: 1997-09-15 | |
| 37 // Purpose: Scheduler class implementation | |
| 38 // Description: This file contains the definitions of the scheduler class | |
| 0 | 39 // member functions that are common to all scheduler |
| 40 // implementations. | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 // | |
| 44 //========================================================================== | |
| 45 | |
| 46 #include <pkgconf/kernel.h> | |
| 47 | |
| 48 #include <cyg/kernel/ktypes.h> // base kernel types | |
| 49 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 50 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 51 #include <cyg/kernel/instrmnt.h> // instrumentation | |
| 52 | |
| 53 #include <cyg/kernel/sched.hxx> // our header | |
| 54 | |
| 55 #include <cyg/kernel/thread.hxx> // thread classes | |
| 56 #include <cyg/kernel/intr.hxx> // Interrupt interface | |
| 57 | |
| 58 #include <cyg/hal/hal_arch.h> // Architecture specific definitions | |
| 59 | |
| 60 #include <cyg/kernel/thread.inl> // thread inlines | |
| 61 | |
| 62 //------------------------------------------------------------------------- | |
| 63 // Some local tracing control - a default. | |
| 64 #ifdef CYGDBG_USE_TRACING | |
| 65 # if !defined( CYGDBG_INFRA_DEBUG_TRACE_ASSERT_SIMPLE ) && \ | |
| 66 !defined( CYGDBG_INFRA_DEBUG_TRACE_ASSERT_FANCY ) | |
| 67 // ie. not a tracing implementation that takes a long time to output | |
| 68 | |
| 69 # ifndef CYGDBG_KERNEL_TRACE_UNLOCK_INNER | |
| 70 # define CYGDBG_KERNEL_TRACE_UNLOCK_INNER | |
| 71 # endif // control not already defined | |
| 72 | |
| 73 # endif // trace implementation not ..._SIMPLE && not ..._FANCY | |
| 74 #endif // CYGDBG_USE_TRACING | |
| 75 | |
| 76 // ------------------------------------------------------------------------- | |
| 77 // Static Cyg_Scheduler class members | |
| 78 | |
| 79 // We start with sched_lock at 1 so that any kernel code we | |
| 80 // call during initialization will not try to reschedule. | |
| 81 | |
| 82 volatile cyg_ucount32 Cyg_Scheduler_Base::sched_lock = 1; | |
| 83 | |
| 84 Cyg_Thread *Cyg_Scheduler_Base::current_thread = NULL; | |
| 85 | |
| 86 cyg_bool Cyg_Scheduler_Base::need_reschedule = false; | |
| 87 | |
| 88 Cyg_Scheduler Cyg_Scheduler::scheduler CYG_INIT_PRIORITY( SCHEDULER ); | |
| 89 | |
| 90 cyg_ucount32 Cyg_Scheduler_Base::thread_switches = 0; | |
| 91 | |
| 92 // ------------------------------------------------------------------------- | |
| 93 // Scheduler unlock function. | |
| 94 // This is only called when the lock is to be decremented to zero and there | |
| 95 // is the potential for real work to be done. Other cases are handled in | |
| 96 // Cyg_Scheduler::unlock() which is an inline. | |
| 97 | |
| 98 void Cyg_Scheduler::unlock_inner() | |
| 99 { | |
| 100 #ifdef CYGDBG_KERNEL_TRACE_UNLOCK_INNER | |
| 101 CYG_REPORT_FUNCTION(); | |
| 102 #endif | |
| 103 | |
| 104 do { | |
| 105 | |
| 106 CYG_PRECONDITION( sched_lock == 1 , "sched_lock not 1" ); | |
| 107 | |
| 108 #ifdef CYGIMP_KERNEL_INTERRUPTS_DSRS | |
| 109 | |
| 110 // Call any pending DSRs. Do this here to ensure that any | |
| 111 // threads that get awakened are properly scheduled. | |
| 112 | |
| 113 if( Cyg_Interrupt::DSRs_pending() ) | |
| 114 Cyg_Interrupt::call_pending_DSRs(); | |
| 115 #endif | |
| 116 | |
| 117 Cyg_Thread *current = current_thread; | |
| 118 | |
| 119 CYG_ASSERTCLASS( current, "Bad current thread" ); | |
| 120 | |
| 121 // If the current thread is going to sleep, or someone | |
| 122 // wants a reschedule, choose another thread to run | |
| 123 | |
| 124 if( current->state != Cyg_Thread::RUNNING || need_reschedule ) { | |
| 125 | |
| 126 CYG_INSTRUMENT_SCHED(RESCHEDULE,0,0); | |
| 127 | |
| 128 // Get the next thread to run from scheduler | |
| 129 Cyg_Thread *next = scheduler.schedule(); | |
| 130 | |
| 131 CYG_CHECK_DATA_PTR( next, "Invalid next thread pointer"); | |
| 132 CYG_ASSERTCLASS( next, "Bad next thread" ); | |
| 133 | |
| 134 if( current != next ) | |
| 135 { | |
| 136 | |
| 137 CYG_INSTRUMENT_THREAD(SWITCH,current,next); | |
| 138 | |
| 139 // Count this thread switch | |
| 140 thread_switches++; | |
| 141 | |
| 142 // Switch contexts | |
| 143 HAL_THREAD_SWITCH_CONTEXT( ¤t->stack_ptr, | |
| 144 &next->stack_ptr ); | |
| 145 | |
| 146 // Worry here about possible compiler | |
| 147 // optimizations across the above call that may try to | |
| 148 // propogate common subexpresions. We would end up | |
| 149 // with the expression from one thread in its | |
| 150 // successor. This is only a worry if we do not save | |
| 151 // and restore the complete register set. We need a | |
| 152 // way of marking functions that return into a | |
| 153 // different context. A temporary fix would be to | |
| 154 // disable CSE (-fdisable-cse) in the compiler. | |
| 155 | |
| 156 // We return here only when the current thread is | |
| 157 // rescheduled. There is a bit of housekeeping to do | |
| 158 // here before we are allowed to go on our way. | |
| 159 | |
| 160 CYG_CHECK_DATA_PTR( current, "Invalid current thread pointer"); | |
| 161 CYG_ASSERTCLASS( current, "Bad current thread" ); | |
| 162 | |
| 163 current_thread = current; // restore current thread pointer | |
| 164 | |
| 165 } | |
| 166 | |
| 167 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 168 // Reset the timeslice counter so that this thread gets a full | |
| 169 // quantum. | |
| 170 reset_timeslice_count(); | |
| 171 #endif | |
| 172 | |
| 173 need_reschedule = false; // finished rescheduling | |
| 174 } | |
| 175 | |
| 2 | 176 HAL_REORDER_BARRIER(); // Make sure everything above has happened |
| 177 // by this point | |
| 0 | 178 sched_lock = 0; // Clear the lock |
| 2 | 179 HAL_REORDER_BARRIER(); |
| 180 | |
| 0 | 181 #ifdef CYGIMP_KERNEL_INTERRUPTS_DSRS |
| 182 | |
| 183 // Now check whether any DSRs got posted during the thread | |
| 184 // switch and if so, go around again. Making this test after | |
| 185 // the lock has been zeroed avoids a race condition in which | |
| 186 // a DSR could have been posted during a reschedule, but would | |
| 187 // not be run until the _next_ time we release the sched lock. | |
| 188 | |
| 189 if( Cyg_Interrupt::DSRs_pending() ) { | |
| 190 sched_lock = 1; // reclaim the lock | |
| 191 continue; // go back to head of loop | |
| 192 } | |
| 193 | |
| 194 #endif | |
| 195 // Otherwise the lock is zero, we can return. | |
| 196 | |
| 197 CYG_POSTCONDITION( sched_lock == 0, "sched_lock not zero" ); | |
| 198 | |
| 199 #ifdef CYGDBG_KERNEL_TRACE_UNLOCK_INNER | |
| 200 CYG_REPORT_RETURN(); | |
| 201 #endif | |
| 202 return; | |
| 203 | |
| 204 } while( 1 ); | |
| 205 | |
| 206 CYG_FAIL( "Should not be executed" ); | |
| 207 } | |
| 208 | |
| 209 // ------------------------------------------------------------------------- | |
| 210 // Start the scheduler. This is called after the initial threads have been | |
| 211 // created to start scheduling. | |
| 212 | |
| 213 void Cyg_Scheduler::start() | |
| 214 { | |
| 215 CYG_REPORT_FUNCTION(); | |
| 216 | |
| 217 // Get the first thread to run from scheduler | |
| 218 register Cyg_Thread *next = scheduler.schedule(); | |
| 219 | |
| 220 CYG_ASSERTCLASS( next, "Bad initial thread" ); | |
| 221 | |
| 222 need_reschedule = false; // finished rescheduling | |
| 223 current_thread = next; // restore current thread pointer | |
| 224 | |
| 2 | 225 #ifdef CYGVAR_KERNEL_COUNTERS_CLOCK |
| 226 // Reference the real time clock. This ensures that at least one | |
| 227 // reference to the kernel_clock.o object exists, without which | |
| 228 // the object will not be included while linking. | |
| 229 CYG_REFERENCE_OBJECT( Cyg_Clock::real_time_clock ); | |
| 230 #endif | |
| 231 | |
| 0 | 232 // Let the interrupts go |
| 233 Cyg_Interrupt::enable_interrupts(); | |
| 234 | |
| 235 HAL_THREAD_LOAD_CONTEXT( &next->stack_ptr ); | |
| 236 | |
| 237 } | |
| 238 | |
| 239 // ------------------------------------------------------------------------- | |
| 240 // Consistency checker | |
| 241 | |
| 242 #ifdef CYGDBG_USE_ASSERTS | |
| 243 | |
| 2 | 244 bool Cyg_Scheduler::check_this( cyg_assert_class_zeal zeal) const |
| 0 | 245 { |
| 246 CYG_REPORT_FUNCTION(); | |
| 247 | |
| 248 // check that we have a non-NULL pointer first | |
| 249 if( this == NULL ) return false; | |
| 250 | |
| 251 switch( zeal ) | |
| 252 { | |
| 253 case cyg_system_test: | |
| 254 case cyg_extreme: | |
| 255 case cyg_thorough: | |
| 256 if( !current_thread->check_this(zeal) ) return false; | |
| 257 case cyg_quick: | |
| 258 case cyg_trivial: | |
| 259 case cyg_none: | |
| 260 default: | |
| 261 break; | |
| 262 }; | |
| 263 | |
| 264 return true; | |
| 265 } | |
| 266 | |
| 267 #endif | |
| 268 | |
| 269 //========================================================================== | |
| 270 // SchedThread members | |
| 271 | |
| 272 // ------------------------------------------------------------------------- | |
| 273 // Constructor | |
| 274 | |
| 275 Cyg_SchedThread::Cyg_SchedThread(Cyg_Thread *thread, CYG_ADDRWORD sched_info) | |
| 276 : Cyg_SchedThread_Implementation(sched_info) | |
| 277 { | |
| 278 CYG_REPORT_FUNCTION(); | |
| 279 | |
| 280 queue = NULL; | |
| 281 | |
| 282 if( Cyg_Scheduler::current_thread == NULL ) | |
| 283 Cyg_Scheduler::current_thread = thread; | |
| 284 | |
| 285 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 286 | |
| 287 mutex_count = 0; | |
| 288 priority_inherited = false; | |
| 289 | |
| 290 #endif | |
| 291 | |
| 292 } | |
| 293 | |
| 294 // ------------------------------------------------------------------------- | |
| 295 // Priority inheritance support. | |
| 296 | |
| 297 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | |
| 298 | |
| 299 // ------------------------------------------------------------------------- | |
| 300 // Inherit the priority of the provided thread if it | |
| 301 // has a higher priority than ours. | |
| 302 | |
| 303 void Cyg_SchedThread::inherit_priority( Cyg_Thread *thread) | |
| 304 { | |
| 305 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 306 | |
| 307 // A simple implementation of priority inheritance. If the other | |
| 308 // thread is of higher priority, reset our priority to his. The | |
| 309 // first time we do this, save our original priority. | |
| 310 | |
| 311 Cyg_Thread *self = CYG_CLASSFROMBASE(Cyg_Thread, | |
| 312 Cyg_SchedThread, | |
| 313 this); | |
| 314 | |
| 315 CYG_ASSERT( mutex_count > 0, "Non-positive mutex count"); | |
| 316 CYG_ASSERT( self != thread, "Trying to inherit from self!"); | |
| 317 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
318 // Compare with *current* priority in case thread has already |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
319 // inherited - for relay case below. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
320 if( thread->get_current_priority() < priority ) |
| 0 | 321 { |
| 322 cyg_priority mypri = priority; | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
323 cyg_bool already_inherited = priority_inherited; |
| 0 | 324 |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
325 // If this is first inheritance, copy the old pri |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
326 // and set inherited flag. We clear it before setting the |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
327 // pri since set_priority() is inheritance aware. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
328 // This is called with the sched locked, so no race conditions. |
| 0 | 329 |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
330 priority_inherited = false; // so that set_prio DTRT |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
331 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
332 self->set_priority( thread->get_current_priority() ); |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
333 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
334 if( !already_inherited ) |
| 0 | 335 original_priority = mypri; |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
336 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
337 priority_inherited = true; // regardless, because it is now |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
338 |
| 0 | 339 } |
| 340 | |
| 341 #endif | |
| 342 } | |
| 343 | |
| 344 // ------------------------------------------------------------------------- | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
345 // Inherit 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
|
346 // 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
|
347 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
348 void Cyg_SchedThread::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
|
349 { |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
350 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
351 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
352 // A simple implementation of priority inheritance. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
353 // At its simplest, this member does nothing. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
354 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
355 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE_RELAY |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
356 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
357 // If there is anyone else waiting, then the *new* owner inherits from |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
358 // the current one, since that is a maxima of the others waiting. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
359 // (It's worth not doing if there's nobody waiting to prevent |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
360 // unneccessary priority skew.) This could be viewed as a discovered |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
361 // priority ceiling. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
362 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
363 if ( !pqueue->empty() ) |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
364 inherit_priority( ex_owner ); |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
365 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
366 #endif |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
367 #endif |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
368 } |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
369 |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
370 // ------------------------------------------------------------------------- |
| 0 | 371 // Lose a priority inheritance |
| 372 | |
| 373 void Cyg_SchedThread::disinherit_priority() | |
| 374 { | |
| 375 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 376 | |
| 377 // A simple implementation of priority inheritance. The | |
| 378 // simplification in this algorithm is that we do not reduce our | |
| 379 // priority until we have freed all mutexes claimed. Hence we can | |
| 380 // continue to run at an artificially high priority even when we | |
| 381 // should not. However, since nested mutexes are rare, the thread | |
| 382 // we have inherited from is likely to be locking the same mutexes | |
| 383 // we are, and mutex claim periods should be very short, the | |
| 384 // performance difference between this and a more complex algorithm | |
| 385 // should be negligible. The most important advantage of this | |
| 386 // algorithm is that it is fast and deterministic. | |
| 387 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
388 // The simplest algorithm also does not cause a 2nd owner (who waited) |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
389 // of a mutex to inherit from 3rd, 4th &c threads that are queueing up |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
390 // when it is awoken. That limitation is avoided when |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
391 // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE_RELAY is also |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
392 // enabled, see above, which passes the raised priority from one thread |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
393 // to the next along with the mutex, like a relay baton. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
394 |
| 0 | 395 Cyg_Thread *self = CYG_CLASSFROMBASE(Cyg_Thread, |
| 396 Cyg_SchedThread, | |
| 397 this); | |
| 398 | |
| 399 CYG_ASSERT( mutex_count >= 0, "Non-positive mutex count"); | |
| 400 | |
| 401 if( mutex_count == 0 && priority_inherited ) | |
| 402 { | |
| 403 priority_inherited = false; | |
| 404 | |
| 405 // Only make an effort if the priority must change | |
| 406 if( priority < original_priority ) | |
| 407 self->set_priority( original_priority ); | |
| 408 | |
| 409 } | |
| 410 | |
| 411 #endif | |
| 412 } | |
| 413 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
414 #endif // CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE of any kind |
| 0 | 415 |
| 416 // ------------------------------------------------------------------------- | |
| 417 // EOF sched/sched.cxx |
