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