Mercurial > flash_v2
comparison packages/kernel/current/src/common/thread.cxx @ 2:443894e2e912 ecos-v1_2_1-release
Block commit of eCos version 1.2.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 12:24:34 +0000 |
| parents | 3111d98ba7b3 |
| children | d376b777e2ce |
comparison
equal
deleted
inserted
replaced
| 1:72f549f0d891 | 2:443894e2e912 |
|---|---|
| 1 //========================================================================== | 1 //========================================================================== |
| 2 // | 2 // |
| 3 // common/thread.cxx | 3 // common/thread.cxx |
| 4 // | 4 // |
| 5 // Thread class implementations | 5 // Thread class implementations |
| 6 // | 6 // |
| 7 //========================================================================== | 7 //========================================================================== |
| 8 //####COPYRIGHTBEGIN#### | 8 //####COPYRIGHTBEGIN#### |
| 9 // | 9 // |
| 10 // ------------------------------------------- | 10 // ------------------------------------------- |
| 20 // | 20 // |
| 21 // The Original Code is eCos - Embedded Cygnus Operating System, released | 21 // The Original Code is eCos - Embedded Cygnus Operating System, released |
| 22 // September 30, 1998. | 22 // September 30, 1998. |
| 23 // | 23 // |
| 24 // The Initial Developer of the Original Code is Cygnus. Portions created | 24 // The Initial Developer of the Original Code is Cygnus. Portions created |
| 25 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | 25 // by Cygnus are Copyright (C) 1998,1999 Cygnus Solutions. All Rights Reserved. |
| 26 // ------------------------------------------- | 26 // ------------------------------------------- |
| 27 // | 27 // |
| 28 //####COPYRIGHTEND#### | 28 //####COPYRIGHTEND#### |
| 29 //========================================================================== | 29 //========================================================================== |
| 30 //#####DESCRIPTIONBEGIN#### | 30 //#####DESCRIPTIONBEGIN#### |
| 31 // | 31 // |
| 32 // Author(s): nickg | 32 // Author(s): nickg |
| 33 // Contributors: nickg | 33 // Contributors: nickg |
| 34 // Date: 1997-09-15 | 34 // Date: 1997-09-15 |
| 35 // Purpose: Thread class implementation | 35 // Purpose: Thread class implementation |
| 36 // Description: This file contains the definitions of the thread class | 36 // Description: This file contains the definitions of the thread class |
| 37 // member functions that are common to all thread implementations. | 37 // member functions that are common to all thread implementations. |
| 38 // | 38 // |
| 39 //####DESCRIPTIONEND#### | 39 //####DESCRIPTIONEND#### |
| 40 // | 40 // |
| 41 //========================================================================== | 41 //========================================================================== |
| 42 | 42 |
| 43 #include <pkgconf/kernel.h> // kernel configuration file | 43 #include <pkgconf/kernel.h> // kernel configuration file |
| 44 | 44 |
| 45 #include <cyg/hal/hal_arch.h> // HAL_REORDER_BARRIER & | |
| 46 // CYGNUM_HAL_STACK_SIZE_TYPICAL | |
| 47 | |
| 45 #include <cyg/kernel/ktypes.h> // base kernel types | 48 #include <cyg/kernel/ktypes.h> // base kernel types |
| 46 #include <cyg/infra/cyg_trac.h> // tracing macros | 49 #include <cyg/infra/cyg_trac.h> // tracing macros |
| 47 #include <cyg/infra/cyg_ass.h> // assertion macros | 50 #include <cyg/infra/cyg_ass.h> // assertion macros |
| 48 #include <cyg/kernel/instrmnt.h> // instrumentation | 51 #include <cyg/kernel/instrmnt.h> // instrumentation |
| 49 | 52 |
| 76 // quantum. | 79 // quantum. |
| 77 Cyg_Scheduler::reset_timeslice_count(); | 80 Cyg_Scheduler::reset_timeslice_count(); |
| 78 #endif | 81 #endif |
| 79 | 82 |
| 80 // Zero the lock | 83 // Zero the lock |
| 81 Cyg_Scheduler::sched_lock = 0; | 84 HAL_REORDER_BARRIER (); // Prevent the compiler from moving |
| 85 Cyg_Scheduler::sched_lock = 0; // the assignment into the code above. | |
| 86 HAL_REORDER_BARRIER(); | |
| 82 | 87 |
| 83 // Call entry point in a loop. | 88 // Call entry point in a loop. |
| 84 | 89 |
| 85 for(;;) | 90 for(;;) |
| 86 { | 91 { |
| 158 inline void * | 163 inline void * |
| 159 operator new(size_t size, Cyg_Thread *ptr) | 164 operator new(size_t size, Cyg_Thread *ptr) |
| 160 { return (void *)ptr; }; | 165 { return (void *)ptr; }; |
| 161 | 166 |
| 162 // Constructor | 167 // Constructor |
| 163 // This constructor is deprecated and should be replaced with the new | |
| 164 // one below. Until that happens, any changes must be made to both | |
| 165 // constructors. | |
| 166 | |
| 167 Cyg_Thread::Cyg_Thread( | |
| 168 cyg_thread_entry *entry, // entry point function | |
| 169 CYG_ADDRWORD entry_data, // entry data | |
| 170 cyg_ucount32 stack_size, // stack size, 0 = use default | |
| 171 CYG_ADDRESS stack_base // stack base, NULL = allocate | |
| 172 ) | |
| 173 : Cyg_HardwareThread(entry, entry_data, stack_size, stack_base), | |
| 174 Cyg_SchedThread(this, CYG_SCHED_DEFAULT_INFO) | |
| 175 #ifdef CYGFUN_KERNEL_THREADS_TIMER | |
| 176 ,timer(this) | |
| 177 #endif | |
| 178 { | |
| 179 CYG_REPORT_FUNCTION(); | |
| 180 | |
| 181 // Start the thread in suspended state. | |
| 182 state = SUSPENDED; | |
| 183 suspend_count = 1; | |
| 184 | |
| 185 // Initialize sleep_reason which is used by kill, release | |
| 186 sleep_reason = NONE; | |
| 187 wake_reason = NONE; | |
| 188 | |
| 189 // Assign a 16 bit id to the thread. | |
| 190 unique_id = next_unique_id++; | |
| 191 | |
| 192 #ifdef CYGVAR_KERNEL_THREADS_DATA | |
| 193 // Zero all per-thread data entries. | |
| 194 for( int i = 0; i < CYGNUM_KERNEL_THREADS_DATA_MAX; i++ ) | |
| 195 thread_data[i] = 0; | |
| 196 #endif | |
| 197 #ifdef CYGVAR_KERNEL_THREADS_NAME | |
| 198 name = 0; | |
| 199 #endif | |
| 200 #ifdef CYGVAR_KERNEL_THREADS_LIST | |
| 201 // Add thread to housekeeping list | |
| 202 add_to_list(); | |
| 203 #endif | |
| 204 | |
| 205 Cyg_Scheduler::scheduler.register_thread(this); | |
| 206 | |
| 207 init_context(this); | |
| 208 | |
| 209 CYG_REPORT_RETURN(); | |
| 210 } | |
| 211 | |
| 212 // ------------------------------------------------------------------------- | |
| 213 // Constructor | |
| 214 // This is an alternative constructor that will become the default | |
| 215 // eventually. | |
| 216 | 168 |
| 217 Cyg_Thread::Cyg_Thread( | 169 Cyg_Thread::Cyg_Thread( |
| 218 CYG_ADDRWORD sched_info, // Scheduling parameter(s) | 170 CYG_ADDRWORD sched_info, // Scheduling parameter(s) |
| 219 cyg_thread_entry *entry, // entry point function | 171 cyg_thread_entry *entry, // entry point function |
| 220 CYG_ADDRWORD entry_data, // entry data | 172 CYG_ADDRWORD entry_data, // entry data |
| 325 // Thread consistency checker. | 277 // Thread consistency checker. |
| 326 | 278 |
| 327 #ifdef CYGDBG_USE_ASSERTS | 279 #ifdef CYGDBG_USE_ASSERTS |
| 328 | 280 |
| 329 bool | 281 bool |
| 330 Cyg_Thread::check_this( cyg_assert_class_zeal zeal) | 282 Cyg_Thread::check_this( cyg_assert_class_zeal zeal) const |
| 331 { | 283 { |
| 332 // CYG_REPORT_FUNCTION(); | 284 // CYG_REPORT_FUNCTION(); |
| 333 | 285 |
| 334 // check that we have a non-NULL pointer first | 286 // check that we have a non-NULL pointer first |
| 335 if( this == NULL ) return false; | 287 if( this == NULL ) return false; |
| 339 case cyg_system_test: | 291 case cyg_system_test: |
| 340 case cyg_extreme: | 292 case cyg_extreme: |
| 341 case cyg_thorough: | 293 case cyg_thorough: |
| 342 if( (state & SUSPENDED) && (suspend_count == 0) ) return false; | 294 if( (state & SUSPENDED) && (suspend_count == 0) ) return false; |
| 343 case cyg_quick: | 295 case cyg_quick: |
| 296 // Check that the stackpointer is within its limits. | |
| 297 // Note: This does not check the current stackpointer value | |
| 298 // of the executing thread. | |
| 299 if( (stack_ptr > (stack_base + stack_size)) || | |
| 300 (stack_ptr < stack_base) ) return false; | |
| 344 case cyg_trivial: | 301 case cyg_trivial: |
| 345 case cyg_none: | 302 case cyg_none: |
| 346 default: | 303 default: |
| 347 break; | 304 break; |
| 348 }; | 305 }; |
| 956 void | 913 void |
| 957 Cyg_Thread::delay( cyg_tick_count delay) | 914 Cyg_Thread::delay( cyg_tick_count delay) |
| 958 { | 915 { |
| 959 CYG_REPORT_FUNCTION(); | 916 CYG_REPORT_FUNCTION(); |
| 960 | 917 |
| 961 #if defined(CYGFUN_KERNEL_THREADS_TIMER) && defined(CYGVAR_KERNEL_COUNTERS_CLOCK) | 918 #ifdef CYGFUN_KERNEL_THREADS_TIMER |
| 962 | 919 |
| 963 CYG_INSTRUMENT_THREAD(DELAY,this,delay); | 920 CYG_INSTRUMENT_THREAD(DELAY,this,delay); |
| 964 | 921 |
| 965 // Prevent preemption | 922 // Prevent preemption |
| 966 Cyg_Scheduler::lock(); | 923 Cyg_Scheduler::lock(); |
| 1141 | 1098 |
| 1142 // ------------------------------------------------------------------------- | 1099 // ------------------------------------------------------------------------- |
| 1143 // Data definitions | 1100 // Data definitions |
| 1144 | 1101 |
| 1145 // stack | 1102 // stack |
| 1146 | 1103 #ifdef CYGNUM_HAL_STACK_SIZE_MINIMUM |
| 1147 #ifdef CYG_HAL_MIPS | 1104 # ifdef CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE |
| 1148 extern char idle_thread_stack[CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE]; | 1105 # if CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE < CYGNUM_HAL_STACK_SIZE_MINIMUM |
| 1149 #else | 1106 |
| 1150 char idle_thread_stack[CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE]; | 1107 // then override the configured stack size |
| 1151 #endif | 1108 # undef CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE |
| 1109 # define CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 1110 | |
| 1111 # endif // CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE < CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 1112 # endif // CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE | |
| 1113 #endif // CYGNUM_HAL_STACK_SIZE_MINIMUM | |
| 1114 | |
| 1115 static char idle_thread_stack[CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE]; | |
| 1152 | 1116 |
| 1153 // Loop counter for debugging/housekeeping | 1117 // Loop counter for debugging/housekeeping |
| 1154 cyg_uint32 idle_thread_loops = 1; | 1118 cyg_uint32 idle_thread_loops = 1; |
| 1155 | 1119 |
| 1156 // ------------------------------------------------------------------------- | 1120 // ------------------------------------------------------------------------- |
