Mercurial > flash_v2
annotate packages/kernel/current/src/sched/bitmap.cxx @ 66:bf00f99aec69 ecos-sw-2000-02-02
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
| author | jlarmour |
|---|---|
| date | Wed, 02 Feb 2000 19:57:02 +0000 |
| parents | c38311975d4f |
| children | 0d0f03f76f6a |
| rev | line source |
|---|---|
| 0 | 1 //========================================================================== |
| 2 // | |
| 2 | 3 // sched/bitmap.cxx |
| 0 | 4 // |
| 2 | 5 // Bitmap scheduler class implementation |
| 0 | 6 // |
| 7 //========================================================================== | |
| 8 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
9 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
10 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
11 // The contents of this file are subject to the Red Hat eCos Public License |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
12 // Version 1.1 (the "License"); you may not use this file except in |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
13 // compliance with the License. You may obtain a copy of the License at |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
14 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
15 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
16 // Software distributed under the License is distributed on an "AS IS" |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
17 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
18 // License for the specific language governing rights and limitations under |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
19 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
20 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
21 // The Original Code is eCos - Embedded Configurable Operating System, |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
22 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
24 // The Initial Developer of the Original Code is Red Hat. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
25 // Portions created by Red Hat are |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
26 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
27 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
28 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
56
diff
changeset
|
29 // |
| 0 | 30 //####COPYRIGHTEND#### |
| 31 //========================================================================== | |
| 32 //#####DESCRIPTIONBEGIN#### | |
| 33 // | |
| 2 | 34 // Author(s): nickg |
| 35 // Contributors: nickg | |
| 36 // Date: 1997-09-16 | |
| 37 // Purpose: Bitmap scheduler class implementation | |
| 38 // Description: This file contains the implementations of | |
| 0 | 39 // Cyg_Scheduler_Implementation and Cyg_SchedThread_Implementation. |
| 40 // | |
| 41 // | |
| 42 //####DESCRIPTIONEND#### | |
| 43 // | |
| 44 //========================================================================== | |
| 45 | |
| 46 #include <pkgconf/kernel.h> | |
| 47 | |
| 48 #include <cyg/kernel/ktypes.h> // base kernel types | |
| 49 #include <cyg/infra/cyg_trac.h> // tracing macros | |
| 50 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 51 | |
| 52 #include <cyg/kernel/sched.hxx> // our header | |
| 53 | |
| 54 #include <cyg/hal/hal_arch.h> // Architecture specific definitions | |
| 55 | |
| 56 #include <cyg/kernel/thread.inl> // thread inlines | |
| 57 #include <cyg/kernel/sched.inl> // scheduler inlines | |
| 58 | |
| 59 #ifdef CYGSEM_KERNEL_SCHED_BITMAP | |
| 60 | |
| 61 //========================================================================== | |
| 62 // Cyg_Scheduler_Implementation class members | |
| 63 | |
| 64 // ------------------------------------------------------------------------- | |
| 65 // Constructor. | |
| 66 | |
| 67 Cyg_Scheduler_Implementation::Cyg_Scheduler_Implementation() | |
| 68 { | |
| 69 CYG_REPORT_FUNCTION(); | |
| 70 | |
| 71 // At present we cannot init run_queue here because the absence of | |
| 72 // ordering of static constructors means that we could do this | |
| 73 // after the static idle thread has been created. (Guess how I | |
| 74 // found this out!) | |
| 75 // run_queue = 0; | |
| 76 | |
| 77 } | |
| 78 | |
| 79 // ------------------------------------------------------------------------- | |
| 80 // Choose the best thread to run next | |
| 81 | |
| 82 Cyg_Thread *Cyg_Scheduler_Implementation::schedule() | |
| 83 { | |
| 84 CYG_REPORT_FUNCTION(); | |
| 85 | |
| 86 // The run queue may _never_ be empty, there is always | |
| 87 // an idle thread at the lowest priority. | |
| 88 | |
| 89 CYG_ASSERT(run_queue != 0, "Run queue empty"); | |
| 90 | |
| 91 cyg_uint32 index; | |
| 92 | |
| 93 HAL_LSBIT_INDEX(index, run_queue); | |
| 94 | |
| 95 return thread_table[index]; | |
| 96 } | |
| 97 | |
| 98 // ------------------------------------------------------------------------- | |
| 99 | |
| 100 void Cyg_Scheduler_Implementation::add_thread(Cyg_Thread *thread) | |
| 101 { | |
| 102 CYG_REPORT_FUNCTION(); | |
| 103 | |
|
56
755351606154
Merge from eCos master repository on 1999-12-01-18:03:05-GMT
jlarmour
parents:
46
diff
changeset
|
104 CYG_ASSERT((CYG_THREAD_MIN_PRIORITY >= thread->priority) |
|
755351606154
Merge from eCos master repository on 1999-12-01-18:03:05-GMT
jlarmour
parents:
46
diff
changeset
|
105 && (CYG_THREAD_MAX_PRIORITY <= thread->priority), |
|
755351606154
Merge from eCos master repository on 1999-12-01-18:03:05-GMT
jlarmour
parents:
46
diff
changeset
|
106 "Priority out of range!"); |
|
755351606154
Merge from eCos master repository on 1999-12-01-18:03:05-GMT
jlarmour
parents:
46
diff
changeset
|
107 |
| 0 | 108 CYG_ASSERT( thread_table[thread->priority] == NULL || |
| 109 thread_table[thread->priority] == thread, | |
| 110 "Duplicate thread priorities" ); | |
| 111 | |
| 112 CYG_ASSERT( (run_queue & (1<<thread->priority)) == 0, | |
| 113 "Run queue bit already set" ); | |
| 114 | |
| 115 // If the thread is on some other queue, remove it | |
| 116 // here. | |
| 117 if( thread->queue != NULL ) | |
| 118 { | |
| 119 thread->queue->remove(thread); | |
| 120 thread->queue = NULL; | |
| 121 } | |
| 122 | |
| 123 run_queue |= 1<<thread->priority; | |
| 124 | |
| 125 // If the new thread is higher priority than the | |
| 126 // current thread, request a reschedule. | |
| 127 | |
| 128 if( thread->priority < Cyg_Scheduler::get_current_thread()->priority ) | |
| 129 need_reschedule = true; | |
| 130 } | |
| 131 | |
| 132 // ------------------------------------------------------------------------- | |
| 133 | |
| 134 void Cyg_Scheduler_Implementation::rem_thread(Cyg_Thread *thread) | |
| 135 { | |
| 136 CYG_REPORT_FUNCTION(); | |
| 137 | |
| 138 CYG_ASSERT( thread_table[thread->priority] == thread, | |
| 139 "Invalid thread priority" ); | |
| 140 | |
| 141 CYG_ASSERT( (run_queue & (1<<thread->priority)) != 0, | |
| 142 "Run queue bit not set" ); | |
| 143 | |
| 144 run_queue &= ~(1<<thread->priority); | |
| 145 | |
| 146 if( thread == Cyg_Scheduler::get_current_thread() ) | |
| 147 need_reschedule = true; | |
| 148 } | |
| 149 | |
| 150 // ------------------------------------------------------------------------- | |
| 151 // register thread with scheduler | |
| 152 | |
| 153 void Cyg_Scheduler_Implementation::register_thread(Cyg_Thread *thread) | |
| 154 { | |
| 155 CYG_REPORT_FUNCTION(); | |
| 156 | |
| 157 thread_table[thread->priority] = thread; | |
| 158 } | |
| 159 | |
| 160 // ------------------------------------------------------------------------- | |
| 161 | |
| 162 // deregister thread | |
| 163 void Cyg_Scheduler_Implementation::deregister_thread(Cyg_Thread *thread) | |
| 164 { | |
| 165 CYG_REPORT_FUNCTION(); | |
| 166 | |
| 167 thread_table[thread->priority] = NULL; | |
| 168 } | |
| 169 | |
| 170 // ------------------------------------------------------------------------- | |
| 171 // Test the given priority for uniqueness | |
| 172 | |
| 173 cyg_bool Cyg_Scheduler_Implementation::unique( cyg_priority priority) | |
| 174 { | |
| 175 CYG_REPORT_FUNCTION(); | |
| 176 | |
| 177 return thread_table[priority] == NULL; | |
| 178 } | |
| 179 | |
| 180 | |
| 181 //========================================================================== | |
| 182 // Cyg_Cyg_SchedThread_Implementation class members | |
| 183 | |
| 184 Cyg_SchedThread_Implementation::Cyg_SchedThread_Implementation | |
| 185 ( | |
| 186 CYG_ADDRWORD sched_info | |
| 187 ) | |
| 188 { | |
| 189 CYG_REPORT_FUNCTION(); | |
| 190 | |
| 191 #if 1 | |
| 192 // Assign this thread's priority to the supplied sched_info | |
| 193 // or the next highest priority available. | |
| 194 | |
| 195 priority = cyg_priority(sched_info); | |
| 196 | |
| 197 while( !Cyg_Scheduler::scheduler.unique(priority) ) | |
| 198 priority++; | |
| 199 | |
| 200 #else | |
| 201 // Assign initial priorities to threads in descending order of | |
| 202 // creation. | |
| 203 | |
| 204 static cyg_priority init_priority = 0; | |
| 205 | |
| 206 priority = init_priority++; | |
| 207 #endif | |
| 208 | |
| 209 } | |
| 210 | |
| 211 // ------------------------------------------------------------------------- | |
| 212 | |
| 213 void Cyg_SchedThread_Implementation::yield() | |
| 214 { | |
| 215 CYG_REPORT_FUNCTION(); | |
| 216 | |
| 217 // We cannot yield in this scheduler | |
| 218 } | |
| 219 | |
| 220 //========================================================================== | |
| 221 // Cyg_ThreadQueue_Implementation class members | |
| 222 | |
| 223 Cyg_ThreadQueue_Implementation::Cyg_ThreadQueue_Implementation() | |
| 224 { | |
| 225 CYG_REPORT_FUNCTION(); | |
| 226 | |
| 227 wait_queue = 0; // empty queue | |
| 2 | 228 |
| 229 CYG_REPORT_RETURN(); | |
| 0 | 230 } |
| 231 | |
| 232 | |
| 233 void Cyg_ThreadQueue_Implementation::enqueue(Cyg_Thread *thread) | |
| 234 { | |
| 235 CYG_REPORT_FUNCTION(); | |
| 236 | |
| 237 wait_queue |= 1<<thread->priority; | |
| 238 thread->queue = CYG_CLASSFROMBASE(Cyg_ThreadQueue, | |
| 239 Cyg_ThreadQueue_Implementation, | |
| 240 this); | |
| 241 } | |
| 242 | |
| 243 // ------------------------------------------------------------------------- | |
| 244 | |
| 245 Cyg_Thread *Cyg_ThreadQueue_Implementation::dequeue() | |
| 246 { | |
| 247 CYG_REPORT_FUNCTION(); | |
| 248 | |
| 249 // Isolate ls bit in run_queue. | |
| 250 cyg_sched_bitmap next_thread = wait_queue & -wait_queue; | |
| 251 | |
| 252 if( next_thread == 0 ) return NULL; | |
| 253 | |
| 254 wait_queue &= ~next_thread; | |
| 255 | |
| 256 cyg_uint32 index; | |
| 257 | |
| 258 HAL_LSBIT_INDEX(index, next_thread); | |
| 259 | |
| 260 Cyg_Thread *thread = Cyg_Scheduler::scheduler.thread_table[index]; | |
| 261 | |
| 262 thread->queue = NULL; | |
| 263 | |
| 264 return thread; | |
| 265 } | |
| 266 | |
| 267 // ------------------------------------------------------------------------- | |
| 268 | |
| 269 Cyg_Thread *Cyg_ThreadQueue_Implementation::highpri() | |
| 270 { | |
| 271 CYG_REPORT_FUNCTION(); | |
| 272 | |
| 273 // Isolate ls bit in run_queue. | |
| 274 cyg_sched_bitmap next_thread = wait_queue & -wait_queue; | |
| 275 | |
| 276 if( next_thread == 0 ) return NULL; | |
| 277 | |
| 278 cyg_uint32 index; | |
| 279 | |
| 280 HAL_LSBIT_INDEX(index, next_thread); | |
| 281 | |
| 282 return Cyg_Scheduler::scheduler.thread_table[index]; | |
| 283 } | |
| 284 | |
| 285 // ------------------------------------------------------------------------- | |
| 286 | |
| 287 void Cyg_ThreadQueue_Implementation::remove(Cyg_Thread *thread) | |
| 288 { | |
| 289 CYG_REPORT_FUNCTION(); | |
| 290 | |
| 291 wait_queue &= ~(1<<thread->priority); | |
| 292 thread->queue = NULL; | |
| 293 } | |
| 294 | |
| 295 #endif | |
| 296 | |
| 297 // ------------------------------------------------------------------------- | |
| 298 // EOF sched/bitmap.cxx |
