Mercurial > ecos
annotate packages/kernel/current/include/thread.inl @ 64:c38311975d4f ecos-sw-2000-01-28
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
| author | jlarmour |
|---|---|
| date | Fri, 28 Jan 2000 04:59:39 +0000 |
| parents | 443894e2e912 |
| children | bf00f99aec69 |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_THREAD_INL |
| 2 #define CYGONCE_KERNEL_THREAD_INL | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // thread.inl |
| 0 | 7 // |
| 2 | 8 // Thread class inlines |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
12 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
13 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
14 // The contents of this file are subject to the Red Hat eCos Public License |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
15 // Version 1.0 (the "License"); you may not use this file except in |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
16 // compliance with the License. You may obtain a copy of the License at |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
17 // http://sourceware.cygnus.com/ecos |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
19 // Software distributed under the License is distributed on an |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
20 // 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:
2
diff
changeset
|
21 // 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:
2
diff
changeset
|
22 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
24 // 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:
2
diff
changeset
|
25 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
26 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
27 // 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:
2
diff
changeset
|
28 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
29 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
30 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
31 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
32 // |
| 0 | 33 //####COPYRIGHTEND#### |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 2 | 37 // Author(s): nickg |
| 38 // Contributors: nickg | |
| 39 // Date: 1997-09-09 | |
| 40 // Purpose: Define inlines for thread classes | |
| 41 // Description: Inline implementations of various member functions defined | |
| 0 | 42 // in various Thread classes. |
| 43 // Usage: | |
| 44 // #include <cyg/kernel/thread.hxx> | |
| 45 // ... | |
| 2 | 46 // #include <cyg/kernel/thread.inl> |
| 47 // ... | |
| 0 | 48 |
| 49 // | |
| 50 //####DESCRIPTIONEND#### | |
| 51 // | |
| 52 //========================================================================== | |
| 53 | |
| 54 #include <cyg/kernel/thread.hxx> | |
| 55 #include <cyg/hal/hal_arch.h> | |
| 56 | |
| 57 #include <cyg/kernel/clock.inl> | |
| 58 | |
| 59 //========================================================================== | |
| 60 // Inlines for Cyg_HardwareThread | |
| 61 | |
| 62 // ------------------------------------------------------------------------- | |
| 63 // Attach a stack to this thread. If there is a HAL defined macro to | |
| 64 // do this, then we use that, otherwise assume a falling stack. | |
| 65 inline void Cyg_HardwareThread::attach_stack(CYG_ADDRESS s_base, cyg_uint32 s_size) | |
| 66 { | |
| 2 | 67 #ifdef CYGNUM_HAL_STACK_SIZE_MINIMUM |
| 68 CYG_ASSERT( s_size >= CYGNUM_HAL_STACK_SIZE_MINIMUM, | |
| 69 "Stack size too small"); | |
| 70 #endif | |
| 0 | 71 stack_base = s_base; |
| 72 stack_size = s_size; | |
| 73 #ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT | |
| 74 stack_limit = s_base; | |
| 75 #endif | |
| 76 | |
| 77 #ifdef HAL_THREAD_ATTACH_STACK | |
| 78 | |
| 79 HAL_THREAD_ATTACH_STACK(stack_ptr, stack_base, stack_size); | |
| 80 | |
| 81 #else | |
| 82 | |
| 83 stack_ptr = stack_base + stack_size; | |
| 84 | |
| 85 #endif | |
| 86 } | |
| 87 | |
| 88 // ------------------------------------------------------------------------- | |
| 89 | |
| 90 inline Cyg_HardwareThread::Cyg_HardwareThread( | |
| 91 cyg_thread_entry *e_point, // entry point function | |
| 92 CYG_ADDRWORD e_data, // entry data | |
| 93 cyg_ucount32 s_size, // stack size, 0 = use default | |
| 94 CYG_ADDRESS s_base // stack base, NULL = allocate | |
| 95 ) | |
| 96 { | |
| 97 entry_point = e_point; | |
| 98 entry_data = e_data; | |
| 99 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT | |
| 100 saved_context = 0; | |
| 101 #endif | |
| 102 | |
| 103 attach_stack( s_base, s_size ); | |
| 104 }; | |
| 105 | |
| 106 // ------------------------------------------------------------------------- | |
| 107 // get the size/base of this thread's stack | |
| 108 | |
| 109 inline CYG_ADDRESS | |
| 110 Cyg_HardwareThread::get_stack_base() | |
| 111 { | |
| 112 return stack_base; | |
| 113 } | |
| 114 | |
| 115 inline cyg_uint32 | |
| 116 Cyg_HardwareThread::get_stack_size() | |
| 117 { | |
| 118 return stack_size; | |
| 119 } | |
| 120 | |
| 121 // ------------------------------------------------------------------------- | |
| 122 | |
| 123 #ifdef CYGDBG_KERNEL_DEBUG_GDB_THREAD_SUPPORT | |
| 124 | |
| 125 // Return the current saved state for this thread. | |
| 126 inline HAL_SavedRegisters *Cyg_HardwareThread::get_saved_context() | |
| 127 { | |
| 128 HAL_SavedRegisters *regs; | |
| 129 if( saved_context != 0 ) regs = saved_context; | |
| 130 else HAL_THREAD_GET_SAVED_REGISTERS( stack_ptr, regs ); | |
| 131 return regs; | |
| 132 } | |
| 133 | |
| 134 inline void Cyg_HardwareThread::set_saved_context(HAL_SavedRegisters *ctx) | |
| 135 { | |
| 136 saved_context = ctx; | |
| 137 } | |
| 138 | |
| 139 #endif | |
| 140 | |
| 141 // ------------------------------------------------------------------------- | |
| 142 // (declare this inline before its first use) | |
| 143 | |
| 144 inline cyg_uint16 Cyg_Thread::get_unique_id() | |
| 145 { | |
| 146 return unique_id; | |
| 147 } | |
| 148 | |
| 149 // ------------------------------------------------------------------------- | |
| 150 // Initialize the context of this thread. | |
| 151 | |
| 152 inline void Cyg_HardwareThread::init_context(Cyg_Thread *thread) | |
| 153 { | |
| 154 #ifdef CYGPKG_INFRA_DEBUG | |
| 155 cyg_uint32 threadid = thread->get_unique_id()*0x01010000; | |
| 156 #else | |
| 157 cyg_uint32 threadid = 0x11110000; | |
| 158 #endif | |
| 159 HAL_THREAD_INIT_CONTEXT( stack_ptr, thread, thread_entry, threadid ); | |
| 160 } | |
| 161 | |
| 162 | |
| 163 | |
| 164 // ------------------------------------------------------------------------- | |
| 165 // Load thread context without saving current context. | |
| 166 // This function is only really here for completeness, the | |
| 167 // kernel generally calls the HAL macros directly. | |
| 168 | |
| 169 inline void Cyg_HardwareThread::load_context() | |
| 170 { | |
| 171 CYG_ADDRESS dummy_stack_ptr; | |
| 172 | |
| 173 HAL_THREAD_SWITCH_CONTEXT( &dummy_stack_ptr, &stack_ptr ); | |
| 174 } | |
| 175 | |
| 176 // ------------------------------------------------------------------------- | |
| 177 // Save current thread's context and load that of the given next thread. | |
| 178 // This function is only really here for completeness, the | |
| 179 // kernel generally calls the HAL macros directly. | |
| 180 | |
| 181 inline void Cyg_HardwareThread::switch_context(Cyg_HardwareThread *next) | |
| 182 { | |
| 183 HAL_THREAD_SWITCH_CONTEXT( &stack_ptr, &next->stack_ptr ); | |
| 184 } | |
| 185 | |
| 186 // ------------------------------------------------------------------------- | |
| 187 // Get and set entry_data. | |
| 188 | |
| 189 inline void Cyg_HardwareThread::set_entry_data( CYG_ADDRWORD data ) | |
| 190 { | |
| 191 entry_data = data; | |
| 192 } | |
| 193 | |
| 194 inline CYG_ADDRWORD Cyg_HardwareThread::get_entry_data() | |
| 195 { | |
| 196 return entry_data; | |
| 197 } | |
| 198 | |
| 199 // ------------------------------------------------------------------------- | |
| 200 // Allocate some memory at the lower end of the stack | |
| 201 // by moving the stack limit pointer. | |
| 202 | |
| 203 #ifdef CYGFUN_KERNEL_THREADS_STACK_LIMIT | |
| 204 | |
| 205 inline void *Cyg_HardwareThread::increment_stack_limit( cyg_ucount32 size) | |
| 206 { | |
| 207 stack_limit += size; | |
| 208 return (void *)(stack_limit - size); | |
| 209 } | |
| 210 | |
| 211 | |
| 212 inline CYG_ADDRESS | |
| 213 Cyg_HardwareThread::get_stack_limit() | |
| 214 { | |
| 215 return stack_limit; | |
| 216 } | |
| 217 | |
| 218 #endif | |
| 219 | |
| 220 //========================================================================== | |
| 221 // Inlines for Cyg_Thread class | |
| 222 | |
| 223 inline Cyg_Thread *Cyg_Thread::self() | |
| 224 { | |
| 225 return Cyg_Scheduler::get_current_thread(); | |
| 226 } | |
| 227 | |
| 228 // ------------------------------------------------------------------------- | |
| 229 | |
| 230 inline void Cyg_Thread::yield() | |
| 231 { | |
| 232 self()->Cyg_SchedThread::yield(); | |
| 233 } | |
| 234 | |
| 235 // ------------------------------------------------------------------------- | |
| 236 | |
| 237 inline void | |
| 238 Cyg_Thread::rotate_queue( cyg_priority pri ) | |
| 239 { | |
| 240 self()->Cyg_SchedThread::rotate_queue( pri ); | |
| 241 } | |
| 2 | 242 |
| 243 // ------------------------------------------------------------------------- | |
| 244 | |
| 245 inline void | |
| 246 Cyg_Thread::to_queue_head( void ) | |
| 247 { | |
| 248 this->Cyg_SchedThread::to_queue_head(); | |
| 249 } | |
| 0 | 250 |
| 251 // ------------------------------------------------------------------------- | |
| 252 | |
| 253 #ifdef CYGIMP_THREAD_PRIORITY | |
| 254 | |
| 255 inline cyg_priority Cyg_Thread::get_priority() | |
| 256 { | |
| 257 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 258 | |
| 259 // If we have an inherited priority, return our original | |
| 260 // priority rather than the current one. | |
| 261 | |
| 262 if( priority_inherited ) return original_priority; | |
| 263 | |
| 264 #endif | |
| 265 | |
| 266 return priority; | |
| 267 } | |
| 268 | |
| 269 // Return the actual dispatching priority of the thread | |
| 270 // regardless of inheritance or scheduling concerns. | |
| 271 inline cyg_priority Cyg_Thread::get_current_priority() | |
| 272 { | |
| 273 return priority; | |
| 274 } | |
| 275 | |
| 276 #endif | |
| 277 | |
| 278 // ------------------------------------------------------------------------- | |
| 279 | |
| 280 inline void Cyg_Thread::set_sleep_reason( cyg_reason reason) | |
| 281 { | |
| 282 self()->sleep_reason = reason; | |
| 283 self()->wake_reason = NONE; | |
| 284 } | |
| 285 | |
| 286 // ------------------------------------------------------------------------- | |
| 287 | |
| 288 inline Cyg_Thread::cyg_reason Cyg_Thread::get_sleep_reason() | |
| 289 { | |
| 290 return sleep_reason; | |
| 291 } | |
| 292 | |
| 293 // ------------------------------------------------------------------------- | |
| 294 | |
| 295 inline void Cyg_Thread::set_wake_reason( cyg_reason reason ) | |
| 296 { | |
| 297 sleep_reason = NONE; | |
| 298 wake_reason = reason; | |
| 299 } | |
| 300 | |
| 301 // ------------------------------------------------------------------------- | |
| 302 | |
| 303 inline Cyg_Thread::cyg_reason Cyg_Thread::get_wake_reason() | |
| 304 { | |
| 305 return wake_reason; | |
| 306 } | |
| 307 | |
| 308 // ------------------------------------------------------------------------- | |
| 309 | |
| 310 inline void Cyg_Thread::set_timer( | |
| 311 cyg_tick_count trigger, | |
| 312 cyg_reason reason | |
| 313 ) | |
| 314 { | |
| 315 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 316 self()->sleep_reason = reason; | |
| 317 self()->wake_reason = NONE; | |
| 318 self()->timer.initialize( trigger); | |
| 319 #endif | |
| 320 } | |
| 321 | |
| 322 // ------------------------------------------------------------------------- | |
| 323 | |
| 324 inline void Cyg_Thread::clear_timer() | |
| 325 { | |
| 326 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 327 self()->timer.disable(); | |
| 328 #endif | |
| 329 } | |
| 330 | |
| 331 // ------------------------------------------------------------------------- | |
| 332 | |
| 333 #ifdef CYGVAR_KERNEL_THREADS_DATA | |
| 334 | |
| 335 inline CYG_ADDRWORD Cyg_Thread::get_data( cyg_ucount32 index ) | |
| 336 { | |
| 337 CYG_ASSERT( index < CYGNUM_KERNEL_THREADS_DATA_MAX, | |
| 338 "Per thread data index out of bounds"); | |
| 339 CYG_ASSERT( (thread_data_map & (1<<index)) == 0, | |
| 340 "Unallocated index used"); | |
| 341 | |
| 342 return self()->thread_data[index]; | |
| 343 } | |
| 344 | |
| 345 inline CYG_ADDRWORD *Cyg_Thread::get_data_ptr( cyg_ucount32 index ) | |
| 346 { | |
| 347 CYG_ASSERT( index < CYGNUM_KERNEL_THREADS_DATA_MAX, | |
| 348 "Per thread data index out of bounds"); | |
| 349 CYG_ASSERT( (thread_data_map & (1<<index)) == 0, | |
| 350 "Unallocated index used"); | |
| 351 | |
| 352 return &(self()->thread_data[index]); | |
| 353 } | |
| 354 | |
| 355 inline void Cyg_Thread::set_data( cyg_ucount32 index, CYG_ADDRWORD data ) | |
| 356 { | |
| 357 CYG_ASSERT( index < CYGNUM_KERNEL_THREADS_DATA_MAX, | |
| 358 "Per thread data index out of bounds"); | |
| 359 CYG_ASSERT( (thread_data_map & (1<<index)) == 0, | |
| 360 "Unallocated index used"); | |
| 361 | |
| 362 thread_data[index] = data; | |
| 363 } | |
| 364 | |
| 365 #endif | |
| 366 | |
| 367 // ------------------------------------------------------------------------- | |
| 368 | |
| 369 #ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 370 | |
| 371 inline char *Cyg_Thread::get_name() | |
| 372 { | |
| 373 return name; | |
| 374 } | |
| 375 | |
| 376 #endif | |
| 377 | |
| 378 // ------------------------------------------------------------------------- | |
| 379 | |
| 380 #ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 381 | |
| 382 inline Cyg_Thread *Cyg_Thread::get_list_head() | |
| 383 { | |
| 384 return thread_list?thread_list->list_next:0; | |
| 385 } | |
| 386 | |
| 387 inline Cyg_Thread *Cyg_Thread::get_list_next() | |
| 388 { | |
| 389 return (this==thread_list)?0:list_next; | |
| 390 } | |
| 391 | |
| 392 #endif | |
| 393 | |
| 394 | |
| 395 // ------------------------------------------------------------------------- | |
| 396 | |
| 397 #ifdef CYGPKG_KERNEL_EXCEPTIONS | |
| 398 | |
| 399 inline void Cyg_Thread::register_exception( | |
| 400 cyg_code exception_number, // exception number | |
| 401 cyg_exception_handler handler, // handler function | |
| 402 CYG_ADDRWORD data, // data argument | |
| 403 cyg_exception_handler **old_handler, // handler function | |
| 404 CYG_ADDRWORD *old_data // data argument | |
| 405 ) | |
| 406 { | |
| 407 self()->exception_control.register_exception( | |
| 408 exception_number, | |
| 409 handler, | |
| 410 data, | |
| 411 old_handler, | |
| 412 old_data | |
| 413 ); | |
| 414 } | |
| 415 | |
| 416 inline void Cyg_Thread::deregister_exception( | |
| 417 cyg_code exception_number // exception number | |
| 418 ) | |
| 419 { | |
| 420 self()->exception_control.deregister_exception( | |
| 421 exception_number | |
| 422 ); | |
| 423 } | |
| 424 | |
| 425 #endif | |
| 426 | |
| 427 //========================================================================== | |
| 428 // Inlines for Cyg_ThreadTimer class | |
| 429 | |
| 430 // ------------------------------------------------------------------------- | |
| 431 #if defined(CYGFUN_KERNEL_THREADS_TIMER) && defined(CYGVAR_KERNEL_COUNTERS_CLOCK) | |
| 432 | |
| 433 inline Cyg_ThreadTimer::Cyg_ThreadTimer( | |
| 434 Cyg_Thread *th | |
| 435 ) | |
| 436 : Cyg_Alarm(Cyg_Clock::real_time_clock, | |
| 437 &alarm, | |
| 438 CYG_ADDRWORD(this) | |
| 439 ) | |
| 440 { | |
| 441 thread = th; | |
| 442 } | |
| 443 | |
| 444 #endif | |
| 445 | |
| 446 //========================================================================== | |
| 447 // Inlines for Cyg_ThreadQueue class | |
| 448 | |
| 449 | |
| 450 inline void Cyg_ThreadQueue::enqueue(Cyg_Thread *thread) | |
| 451 { | |
| 452 Cyg_ThreadQueue_Implementation::enqueue(thread); | |
| 453 } | |
| 454 | |
| 455 // ------------------------------------------------------------------------- | |
| 456 | |
| 457 inline Cyg_Thread *Cyg_ThreadQueue::highpri() | |
| 458 { | |
| 459 return Cyg_ThreadQueue_Implementation::highpri(); | |
| 460 } | |
| 461 | |
| 462 // ------------------------------------------------------------------------- | |
| 463 | |
| 464 inline Cyg_Thread *Cyg_ThreadQueue::dequeue() | |
| 465 { | |
| 466 return Cyg_ThreadQueue_Implementation::dequeue(); | |
| 467 } | |
| 468 | |
| 469 // ------------------------------------------------------------------------- | |
| 470 | |
| 471 inline void Cyg_ThreadQueue::remove(Cyg_Thread *thread) | |
| 472 { | |
| 473 Cyg_ThreadQueue_Implementation::remove(thread); | |
| 474 } | |
| 475 | |
| 476 // ------------------------------------------------------------------------- | |
| 477 | |
| 478 inline cyg_bool Cyg_ThreadQueue::empty() | |
| 479 { | |
| 480 return Cyg_ThreadQueue_Implementation::empty(); | |
| 481 } | |
| 482 | |
| 483 // ------------------------------------------------------------------------- | |
| 484 #endif // ifndef CYGONCE_KERNEL_THREAD_INL | |
| 485 // EOF thread.inl |
