Mercurial > ecos
annotate packages/kernel/current/src/common/thread.cxx @ 8:ece80412419a ecos-sw-1999-05-21
Merge from eCos master repository on 1999-05-21-22:05:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 21 May 1999 15:09:30 +0000 |
| parents | d376b777e2ce |
| children | c38311975d4f |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 2 | 3 // common/thread.cxx |
| 0 | 4 // |
| 2 | 5 // Thread 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 | |
| 2 | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 0 | 26 // ------------------------------------------- |
| 27 // | |
| 28 //####COPYRIGHTEND#### | |
| 29 //========================================================================== | |
| 30 //#####DESCRIPTIONBEGIN#### | |
| 31 // | |
| 2 | 32 // Author(s): nickg |
| 33 // Contributors: nickg | |
| 34 // Date: 1997-09-15 | |
| 35 // Purpose: Thread class implementation | |
| 36 // Description: This file contains the definitions of the thread class | |
| 0 | 37 // member functions that are common to all thread implementations. |
| 38 // | |
| 39 //####DESCRIPTIONEND#### | |
| 40 // | |
| 41 //========================================================================== | |
| 42 | |
| 43 #include <pkgconf/kernel.h> // kernel configuration file | |
| 44 | |
| 2 | 45 #include <cyg/hal/hal_arch.h> // HAL_REORDER_BARRIER & |
| 46 // CYGNUM_HAL_STACK_SIZE_TYPICAL | |
| 47 | |
| 0 | 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/thread.hxx> // our header | |
| 54 | |
| 55 #include <cyg/kernel/intr.hxx> // Interrupt support | |
| 56 | |
| 57 #include <cyg/kernel/thread.inl> // thread inlines | |
| 58 #include <cyg/kernel/sched.inl> // scheduler inlines | |
| 59 #include <cyg/kernel/clock.inl> // clock inlines | |
| 60 | |
| 61 // ========================================================================= | |
| 62 // Cyg_HardwareThread members | |
| 63 | |
| 64 // ------------------------------------------------------------------------- | |
| 65 // Thread entry point. | |
| 66 // This is inserted as the PC value in all initial thread contexts. | |
| 67 // It does some housekeeping and then calls the real entry point. | |
| 68 | |
| 69 void | |
| 70 Cyg_HardwareThread::thread_entry( Cyg_Thread *thread ) | |
| 71 { | |
| 72 CYG_REPORT_FUNCTION(); | |
| 73 | |
| 74 Cyg_Scheduler::scheduler.need_reschedule = false; // finished rescheduling | |
| 75 Cyg_Scheduler::scheduler.current_thread = thread; // restore current thread pointer | |
| 76 | |
|
6
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
77 CYG_INSTRUMENT_THREAD(ENTER,thread,0); |
|
d376b777e2ce
Merge from eCos master repository on 1999-05-14-19:27:43-BST
jlarmour
parents:
2
diff
changeset
|
78 |
| 0 | 79 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE |
| 80 // Reset the timeslice counter so that this thread gets a full | |
| 81 // quantum. | |
| 82 Cyg_Scheduler::reset_timeslice_count(); | |
| 83 #endif | |
| 84 | |
| 85 // Zero the lock | |
| 2 | 86 HAL_REORDER_BARRIER (); // Prevent the compiler from moving |
| 87 Cyg_Scheduler::sched_lock = 0; // the assignment into the code above. | |
| 88 HAL_REORDER_BARRIER(); | |
| 0 | 89 |
| 90 // Call entry point in a loop. | |
| 91 | |
| 92 for(;;) | |
| 93 { | |
| 94 thread->entry_point(thread->entry_data); | |
| 95 thread->exit(); | |
| 96 } | |
| 97 } | |
| 98 | |
| 99 // ========================================================================= | |
| 100 // Cyg_Thread members | |
| 101 | |
| 102 // ------------------------------------------------------------------------- | |
| 103 // Statics and thread list functions | |
| 104 | |
| 105 #ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 106 | |
| 107 // List of all extant threads | |
| 108 Cyg_Thread *Cyg_Thread::thread_list = 0; | |
| 109 | |
| 110 inline void | |
| 111 Cyg_Thread::add_to_list( void ) | |
| 112 { | |
| 113 // Add thread to housekeeping list | |
| 114 Cyg_Scheduler::lock(); | |
| 115 | |
| 116 if( thread_list == 0 ) | |
| 117 list_next = this; | |
| 118 else { | |
| 119 Cyg_Thread *prev = thread_list; | |
| 120 do { | |
| 121 if ( this == prev ) | |
| 122 break; // found it already! | |
| 123 prev = prev->list_next; | |
| 124 } while ( prev != thread_list ); | |
| 125 if ( this != prev ) { | |
| 126 // insert it in the list: | |
| 127 list_next = thread_list->list_next; | |
| 128 thread_list->list_next = this; | |
| 129 } | |
| 130 } | |
| 131 thread_list = this; | |
| 132 | |
| 133 Cyg_Scheduler::unlock(); | |
| 134 } | |
| 135 | |
| 136 inline void | |
| 137 Cyg_Thread::remove_from_list( void ) | |
| 138 { | |
| 139 // remove thread from housekeeping list | |
| 140 Cyg_Scheduler::lock(); | |
| 141 | |
| 142 Cyg_Thread *prev = thread_list; | |
| 143 | |
| 144 do { | |
| 145 if( prev->list_next == this ) { | |
| 146 prev->list_next = list_next; | |
| 147 if( thread_list == this ) | |
| 148 thread_list = list_next; | |
| 149 break; | |
| 150 } | |
| 151 prev = prev->list_next; | |
| 152 } while ( prev != thread_list ); | |
| 153 | |
| 154 Cyg_Scheduler::unlock(); | |
| 155 } | |
| 156 | |
| 157 #endif | |
| 158 | |
| 159 static cyg_uint16 next_unique_id = 1; | |
| 160 | |
| 161 // ------------------------------------------------------------------------- | |
| 162 // Magic new operator to allow the thread constructor to be | |
| 163 // recalled. | |
| 164 | |
| 165 inline void * | |
| 166 operator new(size_t size, Cyg_Thread *ptr) | |
| 167 { return (void *)ptr; }; | |
| 168 | |
| 169 // Constructor | |
| 170 | |
| 171 Cyg_Thread::Cyg_Thread( | |
| 172 CYG_ADDRWORD sched_info, // Scheduling parameter(s) | |
| 173 cyg_thread_entry *entry, // entry point function | |
| 174 CYG_ADDRWORD entry_data, // entry data | |
| 175 char *name_arg, // thread name cookie | |
| 176 CYG_ADDRESS stack_base, // stack base, NULL = allocate | |
| 177 cyg_ucount32 stack_size // stack size, 0 = use default | |
| 178 ) | |
| 179 : Cyg_HardwareThread(entry, entry_data, stack_size, stack_base), | |
| 180 Cyg_SchedThread(this, sched_info) | |
| 181 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 182 ,timer(this) | |
| 183 #endif | |
| 184 { | |
| 185 CYG_REPORT_FUNCTION(); | |
| 186 | |
| 187 // Start the thread in suspended state. | |
| 188 state = SUSPENDED; | |
| 189 suspend_count = 1; | |
| 190 | |
| 191 // Initialize sleep_reason which is used by kill, release | |
| 192 sleep_reason = NONE; | |
| 193 wake_reason = NONE; | |
| 194 | |
| 195 // Assign a 16 bit id to the thread. | |
| 196 unique_id = next_unique_id++; | |
| 197 | |
| 198 #ifdef CYGVAR_KERNEL_THREADS_DATA | |
| 199 // Zero all per-thread data entries. | |
| 200 for( int i = 0; i < CYGNUM_KERNEL_THREADS_DATA_MAX; i++ ) | |
| 201 thread_data[i] = 0; | |
| 202 #endif | |
| 203 #ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 204 name = name_arg; | |
| 205 #endif | |
| 206 #ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 207 // Add thread to housekeeping list | |
| 208 add_to_list(); | |
| 209 #endif | |
| 210 | |
| 211 Cyg_Scheduler::scheduler.register_thread(this); | |
| 212 | |
| 213 init_context(this); | |
| 214 | |
| 215 CYG_REPORT_RETURN(); | |
| 216 } | |
| 217 | |
| 218 | |
| 219 // ------------------------------------------------------------------------- | |
| 220 // Re-initialize this thread. | |
| 221 // We do this by re-invoking the constructor with the original | |
| 222 // arguments, which are still available in the object. | |
| 223 | |
| 224 void | |
| 225 Cyg_Thread::reinitialize() | |
| 226 { | |
| 227 CYG_REPORT_FUNCTION(); | |
| 228 | |
| 229 CYG_ASSERTCLASS( this, "Bad thread"); | |
| 230 CYG_ASSERT( this != Cyg_Scheduler::get_current_thread(), | |
| 231 "Attempt to reinitialize current thread"); | |
| 232 CYG_ASSERT( get_current_queue() == NULL , "Thread is still on a queue"); | |
| 233 | |
| 234 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 235 // Clear the timeout. It is irrelevant whether there was | |
| 236 // actually a timeout pending. | |
| 237 timer.disable(); | |
| 238 #endif | |
| 239 | |
| 240 // Ensure the scheduler has let go of us. | |
| 241 Cyg_Scheduler::scheduler.deregister_thread(this); | |
| 242 | |
| 243 cyg_priority pri = get_priority(); | |
| 244 #ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 245 char * name_arg = name; | |
| 246 #else | |
| 247 char * name_arg = NULL; | |
| 248 #endif | |
| 249 | |
| 250 new(this) Cyg_Thread( pri, | |
| 251 entry_point, entry_data, | |
| 252 name_arg, | |
| 253 stack_base, stack_size ); | |
| 254 // the constructor re-registers the thread with the scheduler. | |
| 255 | |
| 256 CYG_ASSERTCLASS( this, "Thread corrupted by reinitialize"); | |
| 257 | |
| 258 CYG_REPORT_RETURN(); | |
| 259 } | |
| 260 | |
| 261 // ------------------------------------------------------------------------- | |
| 262 // Destructor. | |
| 263 | |
| 264 Cyg_Thread::~Cyg_Thread() | |
| 265 { | |
| 266 CYG_REPORT_FUNCTION(); | |
| 267 | |
| 268 Cyg_Scheduler::scheduler.deregister_thread(this); | |
| 269 | |
| 270 #ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 271 // Remove thread from housekeeping list. | |
| 272 remove_from_list(); | |
| 273 #endif | |
| 274 | |
| 275 CYG_REPORT_RETURN(); | |
| 276 } | |
| 277 | |
| 278 // ------------------------------------------------------------------------- | |
| 279 // Thread consistency checker. | |
| 280 | |
| 281 #ifdef CYGDBG_USE_ASSERTS | |
| 282 | |
| 283 bool | |
| 2 | 284 Cyg_Thread::check_this( cyg_assert_class_zeal zeal) const |
| 0 | 285 { |
| 286 // CYG_REPORT_FUNCTION(); | |
| 287 | |
| 288 // check that we have a non-NULL pointer first | |
| 289 if( this == NULL ) return false; | |
| 290 | |
| 291 switch( zeal ) | |
| 292 { | |
| 293 case cyg_system_test: | |
| 294 case cyg_extreme: | |
| 295 case cyg_thorough: | |
| 296 if( (state & SUSPENDED) && (suspend_count == 0) ) return false; | |
| 297 case cyg_quick: | |
| 2 | 298 // Check that the stackpointer is within its limits. |
| 299 // Note: This does not check the current stackpointer value | |
| 300 // of the executing thread. | |
| 301 if( (stack_ptr > (stack_base + stack_size)) || | |
| 302 (stack_ptr < stack_base) ) return false; | |
| 0 | 303 case cyg_trivial: |
| 304 case cyg_none: | |
| 305 default: | |
| 306 break; | |
| 307 }; | |
| 308 | |
| 309 return true; | |
| 310 } | |
| 311 | |
| 312 #endif | |
| 313 | |
| 314 // ------------------------------------------------------------------------- | |
| 315 // Put the thread to sleep. | |
| 316 // This can only be called by the current thread on itself, hence | |
| 317 // it is a static function. | |
| 318 | |
| 319 void | |
| 320 Cyg_Thread::sleep() | |
| 321 { | |
| 322 CYG_REPORT_FUNCTION(); | |
| 323 | |
| 324 Cyg_Thread *current = Cyg_Scheduler::get_current_thread(); | |
| 325 | |
| 326 CYG_ASSERTCLASS( current, "Bad current thread" ); | |
| 327 | |
| 328 CYG_INSTRUMENT_THREAD(SLEEP,current,0); | |
| 329 | |
| 330 // Prevent preemption | |
| 331 Cyg_Scheduler::lock(); | |
| 332 | |
| 333 // If running, remove from run qs | |
| 334 if ( current->state == RUNNING ) | |
| 335 Cyg_Scheduler::scheduler.rem_thread(current); | |
| 336 | |
| 337 // Set the state | |
| 338 current->state |= SLEEPING; | |
| 339 | |
| 340 // Unlock the scheduler and switch threads | |
| 341 Cyg_Scheduler::unlock(); | |
| 342 | |
| 343 CYG_REPORT_RETURN(); | |
| 344 } | |
| 345 | |
| 346 // ------------------------------------------------------------------------- | |
| 347 // Awaken the thread from sleep. | |
| 348 | |
| 349 void | |
| 350 Cyg_Thread::wake() | |
| 351 { | |
| 352 CYG_REPORT_FUNCTION(); | |
| 353 | |
| 354 CYG_INSTRUMENT_THREAD(WAKE,this,Cyg_Scheduler::current_thread); | |
| 355 | |
| 356 // Prevent preemption | |
| 357 Cyg_Scheduler::lock(); | |
| 358 | |
| 359 if( 0 != (state & SLEEPSET) ) | |
| 360 { | |
| 361 // Set the state | |
| 362 state &= ~SLEEPSET; | |
| 363 | |
| 364 // remove from any queue we were on | |
| 365 remove(); | |
| 366 | |
| 367 // If the thread is now runnable, return it to run queue | |
| 368 if( state == RUNNING ) | |
| 369 Cyg_Scheduler::scheduler.add_thread(this); | |
| 370 | |
| 371 } | |
| 372 | |
| 373 // Unlock the scheduler and maybe switch threads | |
| 374 Cyg_Scheduler::unlock(); | |
| 375 | |
| 376 CYG_REPORT_RETURN(); | |
| 377 } | |
| 378 | |
| 379 // ------------------------------------------------------------------------- | |
| 380 // Put the thread to sleep, with wakeup count. | |
| 381 // This can only be called by the current thread on itself, hence | |
| 382 // it is a static function. | |
| 383 | |
| 384 void | |
| 385 Cyg_Thread::counted_sleep() | |
| 386 { | |
| 387 CYG_REPORT_FUNCTION(); | |
| 388 | |
| 389 Cyg_Thread *current = Cyg_Scheduler::get_current_thread(); | |
| 390 | |
| 391 CYG_ASSERTCLASS( current, "Bad current thread" ); | |
| 392 | |
| 393 CYG_INSTRUMENT_THREAD(SLEEP,current,0); | |
| 394 | |
| 395 // Prevent preemption | |
| 396 Cyg_Scheduler::lock(); | |
| 397 | |
| 398 if ( 0 == current->wakeup_count ) { | |
| 399 set_sleep_reason( Cyg_Thread::WAIT ); | |
| 400 current->sleep(); // prepare to sleep | |
| 401 current->state |= COUNTSLEEP; // Set the state | |
| 402 } | |
| 403 else | |
| 404 // there is a queued wakeup, do not sleep | |
| 405 current->wakeup_count--; | |
| 406 | |
| 407 // Unlock the scheduler and switch threads | |
| 408 Cyg_Scheduler::unlock(); | |
| 409 | |
| 410 // and deal with anything we must do when we return | |
| 411 switch( current->wake_reason ) { | |
| 412 case DESTRUCT: | |
| 413 case EXIT: | |
| 414 current->exit(); | |
| 415 break; | |
| 416 | |
| 417 default: | |
| 418 break; | |
| 419 } | |
| 420 | |
| 421 CYG_REPORT_RETURN(); | |
| 422 } | |
| 423 | |
| 424 // ------------------------------------------------------------------------- | |
| 425 // Put the thread to sleep for a delay, with wakeup count. | |
| 426 // This can only be called by the current thread on itself, hence | |
| 427 // it is a static function. | |
| 428 | |
| 429 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 430 void | |
| 431 Cyg_Thread::counted_sleep( cyg_tick_count delay ) | |
| 432 { | |
| 433 CYG_REPORT_FUNCTION(); | |
| 434 | |
| 435 Cyg_Thread *current = Cyg_Scheduler::get_current_thread(); | |
| 436 | |
| 437 CYG_ASSERTCLASS( current, "Bad current thread" ); | |
| 438 | |
| 439 CYG_INSTRUMENT_THREAD(SLEEP,current,0); | |
| 440 | |
| 441 // Prevent preemption | |
| 442 Cyg_Scheduler::lock(); | |
| 443 | |
| 444 if ( 0 == current->wakeup_count ) { | |
| 445 | |
| 446 // Set the timer (once outside any waiting loop.) | |
| 447 set_timer( Cyg_Clock::real_time_clock->current_value()+delay, | |
| 448 Cyg_Thread::TIMEOUT ); | |
| 449 | |
| 450 // If the timeout is in the past, the wake reason will have been | |
| 451 // set to something other than NONE already. | |
| 452 | |
| 453 if( current->get_wake_reason() == Cyg_Thread::NONE ) | |
| 454 { | |
| 455 set_sleep_reason( Cyg_Thread::TIMEOUT ); | |
| 456 current->sleep(); // prepare to sleep | |
| 457 current->state |= COUNTSLEEP; // Set the state | |
| 458 | |
| 459 CYG_ASSERT( Cyg_Scheduler::get_sched_lock() == 1, | |
| 460 "Called with non-zero scheduler lock"); | |
| 461 | |
| 462 Cyg_Scheduler::unlock(); | |
| 463 Cyg_Scheduler::lock(); | |
| 464 | |
| 465 // clear the timer; if it actually fired, no worries. | |
| 466 clear_timer(); | |
| 467 } | |
| 468 } | |
| 469 else | |
| 470 // there is a queued wakeup, do not sleep | |
| 471 current->wakeup_count--; | |
| 472 | |
| 473 // Unlock the scheduler and switch threads | |
| 474 Cyg_Scheduler::unlock(); | |
| 475 | |
| 476 // and deal with anything we must do when we return | |
| 477 switch( current->wake_reason ) { | |
| 478 case DESTRUCT: | |
| 479 case EXIT: | |
| 480 current->exit(); | |
| 481 break; | |
| 482 | |
| 483 default: | |
| 484 break; | |
| 485 } | |
| 486 | |
| 487 CYG_REPORT_RETURN(); | |
| 488 } | |
| 489 #endif | |
| 490 | |
| 491 // ------------------------------------------------------------------------- | |
| 492 // Awaken the thread from sleep. | |
| 493 | |
| 494 void | |
| 495 Cyg_Thread::counted_wake() | |
| 496 { | |
| 497 CYG_REPORT_FUNCTION(); | |
| 498 | |
| 499 CYG_INSTRUMENT_THREAD(WAKE,this,Cyg_Scheduler::current_thread); | |
| 500 | |
| 501 // Prevent preemption | |
| 502 Cyg_Scheduler::lock(); | |
| 503 | |
| 504 if ( 0 == (state & COUNTSLEEP) ) // already awake, or waiting: | |
| 505 wakeup_count++; // not in a counted sleep anyway. | |
| 506 else { | |
| 507 sleep_reason = NONE; | |
| 508 wake_reason = DONE; | |
| 509 wake(); // and awaken the thread | |
| 510 } | |
| 511 | |
| 512 #ifdef CYGNUM_KERNEL_MAX_COUNTED_WAKE_COUNT_ASSERT | |
| 513 CYG_ASSERT( CYGNUM_KERNEL_MAX_COUNTED_WAKE_COUNT_ASSERT > wakeup_count, | |
| 514 "wakeup_count overflow" ); | |
| 515 #endif | |
| 516 | |
| 517 // Unlock the scheduler and maybe switch threads | |
| 518 Cyg_Scheduler::unlock(); | |
| 519 | |
| 520 CYG_REPORT_RETURN(); | |
| 521 } | |
| 522 | |
| 523 // ------------------------------------------------------------------------- | |
| 524 // Cancel wakeups for this thread and return how many were pending | |
| 525 cyg_uint32 | |
| 526 Cyg_Thread::cancel_counted_wake() | |
| 527 { | |
| 528 CYG_REPORT_FUNCTION(); | |
| 529 | |
| 530 CYG_INSTRUMENT_THREAD(WAKE,this,Cyg_Scheduler::current_thread); | |
| 531 | |
| 532 // Prevent preemption | |
| 533 Cyg_Scheduler::lock(); | |
| 534 | |
| 535 cyg_uint32 result = wakeup_count; | |
| 536 wakeup_count = 0; | |
| 537 | |
| 538 // Unlock the scheduler | |
| 539 Cyg_Scheduler::unlock(); | |
| 540 | |
| 541 CYG_REPORT_RETVAL( result ); | |
| 542 return result; | |
| 543 } | |
| 544 | |
| 545 // ------------------------------------------------------------------------- | |
| 546 // Suspend thread. Increment suspend count and deschedule thread | |
| 547 // if still running. | |
| 548 | |
| 549 void | |
| 550 Cyg_Thread::suspend() | |
| 551 { | |
| 552 CYG_REPORT_FUNCTION(); | |
| 553 | |
| 554 CYG_INSTRUMENT_THREAD(SUSPEND,this,Cyg_Scheduler::current_thread); | |
| 555 | |
| 556 // Prevent preemption | |
| 557 Cyg_Scheduler::lock(); | |
| 558 | |
| 559 suspend_count++; | |
| 560 | |
| 561 #ifdef CYGNUM_KERNEL_MAX_SUSPEND_COUNT_ASSERT | |
| 562 CYG_ASSERT( CYGNUM_KERNEL_MAX_SUSPEND_COUNT_ASSERT > suspend_count, | |
| 563 "suspend_count overflow" ); | |
| 564 #endif | |
| 565 | |
| 566 // If running, remove from run qs | |
| 567 if( state == RUNNING ) | |
| 568 Cyg_Scheduler::scheduler.rem_thread(this); | |
| 569 | |
| 570 // Set the state | |
| 571 state |= SUSPENDED; | |
| 572 | |
| 573 // Unlock the scheduler and maybe switch threads | |
| 574 Cyg_Scheduler::unlock(); | |
| 575 | |
| 576 CYG_REPORT_RETURN(); | |
| 577 } | |
| 578 | |
| 579 // ------------------------------------------------------------------------- | |
| 580 // Resume thread. Decrement suspend count and reschedule if it | |
| 581 // is zero. | |
| 582 | |
| 583 void | |
| 584 Cyg_Thread::resume() | |
| 585 { | |
| 586 CYG_REPORT_FUNCTION(); | |
| 587 | |
| 588 CYG_INSTRUMENT_THREAD(RESUME,this,Cyg_Scheduler::current_thread); | |
| 589 | |
| 590 // Prevent preemption | |
| 591 Cyg_Scheduler::lock(); | |
| 592 | |
| 593 // If we are about to zero the count, clear the state bit and | |
| 594 // reschedule the thread if possible. | |
| 595 | |
| 596 if( suspend_count == 1 ) | |
| 597 { | |
| 598 suspend_count = 0; | |
| 599 | |
| 600 CYG_ASSERT( (state & SUSPENDED) != 0, "SUSPENDED bit not set" ); | |
| 601 | |
| 602 // Set the state | |
| 603 state &= ~SUSPENDED; | |
| 604 | |
| 605 // Return thread to scheduler if runnable | |
| 606 if( state == RUNNING ) | |
| 607 Cyg_Scheduler::scheduler.add_thread(this); | |
| 608 } | |
| 609 else | |
| 610 if( suspend_count > 0 ) | |
| 611 suspend_count--; | |
| 612 // else ignore attempt to resume | |
| 613 | |
| 614 // Unlock the scheduler and maybe switch threads | |
| 615 Cyg_Scheduler::unlock(); | |
| 616 CYG_REPORT_RETURN(); | |
| 617 } | |
| 618 | |
| 619 // ------------------------------------------------------------------------- | |
| 620 // Forced Resume thread. Zero suspend count and reschedule... | |
| 621 | |
| 622 void | |
| 623 Cyg_Thread::force_resume() | |
| 624 { | |
| 625 CYG_REPORT_FUNCTION(); | |
| 626 | |
| 627 CYG_INSTRUMENT_THREAD(RESUME,this,Cyg_Scheduler::current_thread); | |
| 628 | |
| 629 // Prevent preemption | |
| 630 Cyg_Scheduler::lock(); | |
| 631 | |
| 632 // If we are about to zero the count, clear the state bit and | |
| 633 // reschedule the thread if possible. | |
| 634 | |
| 635 if ( 0 < suspend_count ) { | |
| 636 suspend_count = 0; | |
| 637 | |
| 638 CYG_ASSERT( (state & SUSPENDED) != 0, "SUSPENDED bit not set" ); | |
| 639 | |
| 640 // Set the state | |
| 641 state &= ~SUSPENDED; | |
| 642 | |
| 643 // Return thread to scheduler if runnable | |
| 644 if( state == RUNNING ) | |
| 645 Cyg_Scheduler::scheduler.add_thread(this); | |
| 646 } | |
| 647 | |
| 648 // Unlock the scheduler and maybe switch threads | |
| 649 Cyg_Scheduler::unlock(); | |
| 650 CYG_REPORT_RETURN(); | |
| 651 } | |
| 652 | |
| 653 // ------------------------------------------------------------------------- | |
| 654 // Force thread to wake up from a sleep with a wake_reason of | |
| 655 // BREAK. It is the responsibility of the woken thread to detect | |
| 656 // the release() and do the right thing. | |
| 657 | |
| 658 void | |
| 659 Cyg_Thread::release() | |
| 660 { | |
| 661 CYG_REPORT_FUNCTION(); | |
| 662 // Prevent preemption | |
| 663 Cyg_Scheduler::lock(); | |
| 664 | |
| 665 // If the thread is in any of the sleep states, set the | |
| 666 // wake reason and wake it up. | |
| 667 | |
| 668 switch( sleep_reason ) | |
| 669 { | |
| 670 | |
| 671 case NONE: | |
| 672 // The thread is not sleeping for any reason, do nothing. | |
| 673 // drop through... | |
| 674 | |
| 675 case DESTRUCT: | |
| 676 case BREAK: | |
| 677 case EXIT: | |
| 678 case DONE: | |
| 679 // Do nothing in any of these cases. They are here to | |
| 680 // keep the compiler happy. | |
| 681 | |
| 682 Cyg_Scheduler::unlock(); | |
| 683 CYG_REPORT_RETURN(); | |
| 684 return; | |
| 685 | |
| 686 case WAIT: | |
| 687 // The thread was waiting for some sync object to do | |
| 688 // something. | |
| 689 // drop through... | |
| 690 | |
| 691 case TIMEOUT: | |
| 692 // The thread was waiting on a sync object with a timeout. | |
| 693 // drop through... | |
| 694 | |
| 695 case DELAY: | |
| 696 // The thread was simply delaying, unless it has been | |
| 697 // woken up for some other reason, wake it now. | |
| 698 sleep_reason = NONE; | |
| 699 wake_reason = BREAK; | |
| 700 break; | |
| 701 } | |
| 702 | |
| 703 wake(); | |
| 704 | |
| 705 // Allow preemption | |
| 706 Cyg_Scheduler::unlock(); | |
| 707 | |
| 708 CYG_REPORT_RETURN(); | |
| 709 } | |
| 710 | |
| 711 // ------------------------------------------------------------------------- | |
| 712 // Exit thread. This puts the thread into EXITED state. | |
| 713 | |
| 714 void | |
| 715 Cyg_Thread::exit() | |
| 716 { | |
| 717 // The thread should never return from this function. | |
| 718 | |
| 719 Cyg_Thread *self = Cyg_Thread::self(); | |
| 720 | |
| 721 Cyg_Scheduler::lock(); | |
| 722 | |
| 723 // clear the timer; if there was none, no worries. | |
| 724 clear_timer(); | |
| 725 | |
| 726 self->state = EXITED; | |
| 727 | |
| 728 Cyg_Scheduler::scheduler.rem_thread(self); | |
| 729 | |
| 730 // Un-nest any scheduler locks we have until we | |
| 731 // suspend. | |
| 732 for( ;; ) Cyg_Scheduler::unlock(); | |
| 733 } | |
| 734 | |
| 735 // ------------------------------------------------------------------------- | |
| 736 // Kill thread. Force the thread into EXITED state externally, or | |
| 737 // make it wake up and call exit(). | |
| 738 | |
| 739 void | |
| 740 Cyg_Thread::kill() | |
| 741 { | |
| 742 CYG_REPORT_FUNCTION(); | |
| 743 // If this is called by the current thread on itself, | |
| 744 // just call exit(), which is what he should have done | |
| 745 // in the first place. | |
| 746 if( this == Cyg_Scheduler::get_current_thread() ) | |
| 747 exit(); | |
| 748 | |
| 749 // Prevent preemption | |
| 750 Cyg_Scheduler::lock(); | |
| 751 | |
| 752 // We are killing someone else. Find out what state he is | |
| 753 // in and force him to wakeup and call exit(). | |
| 754 | |
| 755 force_resume(); // this is necessary for when | |
| 756 // he is asleep AND suspended. | |
| 757 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 758 timer.disable(); // and make sure the timer | |
| 759 // does not persist. | |
| 760 #endif | |
| 761 | |
|
8
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
6
diff
changeset
|
762 if ( EXIT != wake_reason ) switch( sleep_reason ) { |
|
ece80412419a
Merge from eCos master repository on 1999-05-21-22:05:54-BST
jlarmour
parents:
6
diff
changeset
|
763 // Only do any of this if the thread is not in pending death already: |
| 0 | 764 |
| 765 case NONE: | |
| 766 // The thread is not sleeping for any reason, it must be | |
| 767 // on a run queue. | |
| 768 // We can safely deschedule and set its state. | |
| 769 if( state == RUNNING ) Cyg_Scheduler::scheduler.rem_thread(this); | |
| 770 state = EXITED; | |
| 771 break; | |
| 772 | |
| 773 case DESTRUCT: | |
| 774 case BREAK: | |
| 775 case EXIT: | |
| 776 case DONE: | |
| 777 // Do nothing in any of these cases. They are here to | |
| 778 // keep the compiler happy. | |
| 779 | |
| 780 Cyg_Scheduler::unlock(); | |
| 781 CYG_REPORT_RETURN(); | |
| 782 return; | |
| 783 | |
| 784 case WAIT: | |
| 785 // The thread was waiting for some sync object to do | |
| 786 // something. | |
| 787 // drop through... | |
| 788 | |
| 789 case TIMEOUT: | |
| 790 // The thread was waiting on a sync object with a timeout. | |
| 791 // drop through... | |
| 792 | |
| 793 case DELAY: | |
| 794 // The thread was simply delaying, unless it has been | |
| 795 // woken up for some other reason, wake it now. | |
| 796 sleep_reason = NONE; | |
| 797 wake_reason = EXIT; | |
| 798 break; | |
| 799 } | |
| 800 | |
| 801 wake(); | |
| 802 | |
| 803 // Allow preemption | |
| 804 Cyg_Scheduler::unlock(); | |
| 805 CYG_REPORT_RETURN(); | |
| 806 } | |
| 807 | |
| 808 // ------------------------------------------------------------------------- | |
| 809 // Set thread priority | |
| 810 | |
| 811 #ifdef CYGIMP_THREAD_PRIORITY | |
| 812 | |
| 813 void | |
| 814 Cyg_Thread::set_priority( cyg_priority new_priority ) | |
| 815 { | |
| 816 CYG_REPORT_FUNCTION(); | |
| 817 | |
| 818 // CYG_ASSERT( new_priority >= CYG_THREAD_MAX_PRIORITY, "Priority out of range"); | |
| 819 // CYG_ASSERT( new_priority <= CYG_THREAD_MIN_PRIORITY, "Priority out of range"); | |
| 820 | |
| 821 CYG_INSTRUMENT_THREAD(PRIORITY,this,priority); | |
| 822 | |
| 823 // Prevent preemption | |
| 824 Cyg_Scheduler::lock(); | |
| 825 | |
| 826 Cyg_ThreadQueue *queue = NULL; | |
| 827 | |
| 828 // If running, remove from run qs | |
| 829 if( state == RUNNING ) | |
| 830 Cyg_Scheduler::scheduler.rem_thread(this); | |
| 831 else if( state & SLEEPING ) | |
| 832 { | |
| 833 // Remove thread from current queue. | |
| 834 queue = get_current_queue(); | |
| 835 // if indeed we are on a queue | |
| 836 if ( NULL != queue ) { | |
| 837 CYG_CHECK_DATA_PTR(queue, "Bad queue pointer"); | |
| 838 remove(); | |
| 839 } | |
| 840 } | |
| 841 | |
| 842 Cyg_Scheduler::scheduler.deregister_thread(this); | |
| 843 | |
| 844 #if CYG_SCHED_UNIQUE_PRIORITIES | |
| 845 | |
| 846 // Check that there are no other threads at this priority. | |
| 847 // If so, leave is as it is. | |
| 848 | |
| 849 CYG_ASSERT( Cyg_Scheduler::scheduler.unique(new_priority), "Priority not unique"); | |
| 850 | |
| 851 if( Cyg_Scheduler::scheduler.unique(new_priority) ) | |
| 852 priority = new_priority; | |
| 853 | |
| 854 #else // !CYG_SCHED_UNIQUE_PRIORITIES | |
| 855 | |
| 856 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 857 | |
| 858 // When we have priority inheritance, we must update the original | |
| 859 // priority and not the inherited one. If the new priority is | |
| 860 // better than the current inherited one, then use that | |
| 861 // immediately. We remain in inherited state to avoid problems | |
| 862 // with multiple mutex inheritances. | |
| 863 | |
| 864 if( priority_inherited ) | |
| 865 { | |
| 866 original_priority = new_priority; | |
| 867 if( priority > new_priority ) priority = new_priority; | |
| 868 } | |
| 869 else priority = new_priority; | |
| 870 | |
| 871 #else | |
| 872 | |
| 873 priority = new_priority; | |
| 874 | |
| 875 #endif | |
| 876 | |
| 877 #endif // CYG_SCHED_UNIQUE_PRIORITIES | |
| 878 | |
| 879 Cyg_Scheduler::scheduler.register_thread(this); | |
| 880 | |
| 881 // Return thread to scheduler if runnable | |
| 882 if( state == RUNNING ) | |
| 883 Cyg_Scheduler::scheduler.add_thread(this); | |
| 884 else if ( state & SLEEPING ) | |
| 885 { | |
| 886 // return to current queue | |
| 887 // if indeed we are on a queue | |
| 888 if ( NULL != queue ) { | |
| 889 CYG_CHECK_DATA_PTR(queue, "Bad queue pointer"); | |
| 890 queue->enqueue(this); | |
| 891 } | |
| 892 } | |
| 893 | |
| 894 // If the current thread is being reprioritized, set the | |
| 895 // reschedule flag to ensure that it gets rescheduled if | |
| 896 // necessary. (Strictly we only need to do this if the new | |
| 897 // priority is less than that of some other runnable thread, in | |
| 898 // practice checking that is as expensive as what the scheduler | |
| 899 // will do anyway). | |
| 900 | |
| 901 if( this == Cyg_Scheduler::get_current_thread() ) | |
| 902 Cyg_Scheduler::need_reschedule = true; | |
| 903 | |
| 904 // Unlock the scheduler and maybe switch threads | |
| 905 Cyg_Scheduler::unlock(); | |
| 906 CYG_REPORT_RETURN(); | |
| 907 } | |
| 908 | |
| 909 #endif | |
| 910 | |
| 911 | |
| 912 // ------------------------------------------------------------------------- | |
| 913 // Thread delay function | |
| 914 | |
| 915 void | |
| 916 Cyg_Thread::delay( cyg_tick_count delay) | |
| 917 { | |
| 918 CYG_REPORT_FUNCTION(); | |
| 919 | |
| 2 | 920 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
| 0 | 921 |
| 922 CYG_INSTRUMENT_THREAD(DELAY,this,delay); | |
| 923 | |
| 924 // Prevent preemption | |
| 925 Cyg_Scheduler::lock(); | |
| 926 | |
| 927 sleep(); | |
| 928 | |
| 929 set_timer( Cyg_Clock::real_time_clock->current_value()+delay, DELAY ); | |
| 930 | |
| 931 // Unlock the scheduler and maybe switch threads | |
| 932 Cyg_Scheduler::unlock(); | |
| 933 | |
| 934 // Clear the timeout. It is irrelevant whether the alarm has | |
| 935 // actually gone off or not. | |
| 936 clear_timer(); | |
| 937 | |
| 938 // and deal with anything else we must do when we return | |
| 939 switch( wake_reason ) { | |
| 940 case DESTRUCT: | |
| 941 case EXIT: | |
| 942 exit(); | |
| 943 break; | |
| 944 | |
| 945 default: | |
| 946 break; | |
| 947 } | |
| 948 #endif | |
| 949 CYG_REPORT_RETURN(); | |
| 950 } | |
| 951 | |
| 952 // ------------------------------------------------------------------------- | |
| 953 // | |
| 954 | |
| 955 #ifdef CYGPKG_KERNEL_EXCEPTIONS | |
| 956 | |
| 957 void | |
| 958 Cyg_Thread::deliver_exception( | |
| 959 cyg_code exception_number, // exception being raised | |
| 960 CYG_ADDRWORD exception_info // exception specific info | |
| 961 ) | |
| 962 { | |
| 963 if( this == Cyg_Scheduler::get_current_thread() ) | |
| 964 { | |
| 965 // Delivering to current thread, probably as a result | |
| 966 // of a real hardware exception. Simply invoke the appropriate | |
| 967 // handler. | |
| 968 | |
| 969 exception_control.deliver_exception( exception_number, exception_info ); | |
| 970 } | |
| 971 #ifdef CYGIMP_EXCEPTION_ASYNC | |
| 972 else | |
| 973 { | |
| 974 // Delivering to another thread, probably as a result of one thread | |
| 975 // invoking this function on another thread. Adjust the other thread's | |
| 976 // state to make it execute the exception routine when it next runs. | |
| 977 | |
| 978 // At present there is an unresolved problem here. We do not know what | |
| 979 // state the destination thread is in. It may not be a suitable point at | |
| 980 // which to invoke an exception routine. In most cases the exception | |
| 981 // routine will be run in the scheduler thread switch code, where the world is | |
| 982 // in an inconsistent state. We really need to run the routine at the | |
| 983 // end of unlock_inner(). However this would add extra code to the scheduler, | |
| 984 // and require a way of storing pending exceptions. So for now this option is | |
| 985 // disabled and not yet implemented, it may never be. | |
| 986 | |
| 987 } | |
| 988 #endif | |
| 989 } | |
| 990 | |
| 991 #endif | |
| 992 | |
| 993 // ------------------------------------------------------------------------- | |
| 994 // Per-thread data support | |
| 995 | |
| 996 #ifdef CYGVAR_KERNEL_THREADS_DATA | |
| 997 | |
| 998 // Set the data map bits for each free slot in the data array. | |
| 999 cyg_ucount32 Cyg_Thread::thread_data_map = (~CYGNUM_KERNEL_THREADS_DATA_ALL) & | |
| 1000 ((1<<CYGNUM_KERNEL_THREADS_DATA_MAX)-1); | |
| 1001 | |
| 1002 cyg_ucount32 | |
| 1003 Cyg_Thread::new_data_index() | |
| 1004 { | |
| 1005 Cyg_Scheduler::lock(); | |
| 1006 | |
| 1007 cyg_ucount32 index; | |
| 1008 | |
| 1009 CYG_ASSERT( thread_data_map != 0 , "No more thread data indexes"); | |
| 1010 | |
| 1011 // find ls set bit | |
| 1012 HAL_LSBIT_INDEX( index, thread_data_map ); | |
| 1013 | |
| 1014 // clear the bit | |
| 1015 thread_data_map &= ~(1<<index); | |
| 1016 | |
| 1017 Cyg_Scheduler::unlock(); | |
| 1018 | |
| 1019 return index; | |
| 1020 } | |
| 1021 | |
| 1022 void Cyg_Thread::free_data_index( cyg_ucount32 index ) | |
| 1023 { | |
| 1024 Cyg_Scheduler::lock(); | |
| 1025 | |
| 1026 thread_data_map |= (1<<index); | |
| 1027 | |
| 1028 Cyg_Scheduler::unlock(); | |
| 1029 } | |
| 1030 | |
| 1031 | |
| 1032 #endif | |
| 1033 | |
| 1034 // ========================================================================= | |
| 1035 // Cyg_ThreadTimer member functions | |
| 1036 | |
| 1037 // ------------------------------------------------------------------------- | |
| 1038 // Timer alarm function. Inspect the sleep_reason and if necessary wake | |
| 1039 // up the thread with an appropriate wake_reason. | |
| 1040 | |
| 1041 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 1042 | |
| 1043 void | |
| 1044 Cyg_ThreadTimer::alarm( | |
| 1045 Cyg_Alarm *alarm, | |
| 1046 CYG_ADDRWORD data | |
| 1047 ) | |
| 1048 { | |
| 1049 CYG_REPORT_FUNCTION(); | |
| 1050 | |
| 1051 Cyg_ThreadTimer *self = (Cyg_ThreadTimer *)data; | |
| 1052 Cyg_Thread *thread = self->thread; | |
| 1053 | |
| 1054 CYG_INSTRUMENT_THREAD(ALARM, 0, 0); | |
| 1055 | |
| 1056 Cyg_Scheduler::lock(); | |
| 1057 | |
| 1058 Cyg_Thread::cyg_reason sleep_reason = thread->get_sleep_reason(); | |
| 1059 | |
| 1060 switch( sleep_reason ) { | |
| 1061 | |
| 1062 case Cyg_Thread::DESTRUCT: | |
| 1063 case Cyg_Thread::BREAK: | |
| 1064 case Cyg_Thread::EXIT: | |
| 1065 case Cyg_Thread::NONE: | |
| 1066 case Cyg_Thread::WAIT: | |
| 1067 case Cyg_Thread::DONE: | |
| 1068 // Do nothing in any of these cases. Most are here to | |
| 1069 // keep the compiler happy. | |
| 1070 Cyg_Scheduler::unlock(); | |
| 1071 CYG_REPORT_RETURN(); | |
| 1072 return; | |
| 1073 | |
| 1074 case Cyg_Thread::DELAY: | |
| 1075 // The thread was simply delaying, unless it has been | |
| 1076 // woken up for some other reason, wake it now. | |
| 1077 thread->set_wake_reason(Cyg_Thread::DONE); | |
| 1078 break; | |
| 1079 | |
| 1080 case Cyg_Thread::TIMEOUT: | |
| 1081 // The thread has timed out, set the wake reason to | |
| 1082 // TIMEOUT and restart. | |
| 1083 thread->set_wake_reason(Cyg_Thread::TIMEOUT); | |
| 1084 break; | |
| 1085 } | |
| 1086 | |
| 1087 thread->wake(); | |
| 1088 | |
| 1089 Cyg_Scheduler::unlock(); | |
| 1090 CYG_REPORT_RETURN(); | |
| 1091 } | |
| 1092 | |
| 1093 #endif | |
| 1094 | |
| 1095 // ========================================================================= | |
| 1096 // The Idle thread | |
| 1097 // The idle thread is implemented as a single instance of the | |
| 1098 // Cyg_IdleThread class. This is so that it can be initialized before | |
| 1099 // main in a static constructor. | |
| 1100 | |
| 1101 // ------------------------------------------------------------------------- | |
| 1102 // Data definitions | |
| 1103 | |
| 1104 // stack | |
| 2 | 1105 #ifdef CYGNUM_HAL_STACK_SIZE_MINIMUM |
| 1106 # ifdef CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE | |
| 1107 # if CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE < CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 0 | 1108 |
| 2 | 1109 // then override the configured stack size |
| 1110 # undef CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE | |
| 1111 # define CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 1112 | |
| 1113 # endif // CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE < CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 1114 # endif // CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE | |
| 1115 #endif // CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 1116 | |
| 1117 static char idle_thread_stack[CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE]; | |
| 0 | 1118 |
| 1119 // Loop counter for debugging/housekeeping | |
| 1120 cyg_uint32 idle_thread_loops = 1; | |
| 1121 | |
| 1122 // ------------------------------------------------------------------------- | |
| 1123 // Idle thread code. | |
| 1124 | |
| 1125 void | |
| 1126 idle_thread_main( CYG_ADDRESS data ) | |
| 1127 { | |
| 1128 CYG_REPORT_FUNCTION(); | |
| 1129 | |
| 1130 for(;;) | |
| 1131 { | |
| 1132 idle_thread_loops++; | |
| 1133 | |
| 1134 HAL_IDLE_THREAD_ACTION(idle_thread_loops); | |
| 1135 | |
| 1136 #if 0 | |
| 1137 // For testing, it is useful to be able to fake | |
| 1138 // clock interrupts in the idle thread. | |
| 1139 | |
| 1140 Cyg_Clock::real_time_clock->tick(); | |
| 1141 #endif | |
| 1142 #ifdef CYGIMP_IDLE_THREAD_YIELD | |
| 1143 // In single priority and non-preemptive systems, | |
| 1144 // the idle thread should yield repeatedly to | |
| 1145 // other threads. | |
| 1146 Cyg_Thread::yield(); | |
| 1147 #endif | |
| 1148 } | |
| 1149 } | |
| 1150 | |
| 1151 // ------------------------------------------------------------------------- | |
| 1152 // Idle thread class | |
| 1153 | |
| 1154 class Cyg_IdleThread : public Cyg_Thread | |
| 1155 { | |
| 1156 public: | |
| 1157 Cyg_IdleThread( | |
| 1158 cyg_thread_entry *entry, // entry point function | |
| 1159 CYG_ADDRWORD entry_data, // entry data | |
| 1160 cyg_ucount32 stack_size = 0, // stack size, 0 = use default | |
| 1161 CYG_ADDRESS stack_base = 0 // stack base, NULL = allocate | |
| 1162 ); | |
| 1163 | |
| 1164 }; | |
| 1165 | |
| 1166 // ------------------------------------------------------------------------- | |
| 1167 // Idle threads constructor | |
| 1168 | |
| 1169 Cyg_IdleThread::Cyg_IdleThread( | |
| 1170 cyg_thread_entry *entry, // entry point function | |
| 1171 CYG_ADDRWORD entry_data, // entry data | |
| 1172 cyg_ucount32 stack_size, // stack size, 0 = use default | |
| 1173 CYG_ADDRESS stack_base // stack base, NULL = allocate | |
| 1174 ) | |
| 1175 : Cyg_Thread( CYG_THREAD_MIN_PRIORITY, | |
| 1176 entry, | |
| 1177 entry_data, | |
| 1178 "Idle Thread", | |
| 1179 stack_base, | |
| 1180 stack_size) | |
| 1181 { | |
| 1182 CYG_REPORT_FUNCTION(); | |
| 1183 | |
| 1184 resume(); | |
| 1185 CYG_REPORT_RETURN(); | |
| 1186 } | |
| 1187 | |
| 1188 // ------------------------------------------------------------------------- | |
| 1189 // Instantiate the idle thread | |
| 1190 | |
| 1191 Cyg_IdleThread idle_thread CYG_INIT_PRIORITY( IDLE_THREAD ) = | |
| 1192 Cyg_IdleThread( idle_thread_main, | |
| 1193 0, | |
| 1194 CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE, | |
| 1195 CYG_ADDRESS(idle_thread_stack) | |
| 1196 ); | |
| 1197 | |
| 1198 | |
| 1199 // ------------------------------------------------------------------------- | |
| 1200 // EOF common/thread.cxx |
