Mercurial > ecos
annotate packages/kernel/current/include/mlqueue.hxx @ 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 | 6ed91473a1cd |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_MLQUEUE_HXX |
| 2 #define CYGONCE_KERNEL_MLQUEUE_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // mlqueue.hxx |
| 0 | 7 // |
| 2 | 8 // Multi-Level Queue scheduler class declarations |
| 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 |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
15 // 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:
2
diff
changeset
|
16 // 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
|
17 // http://www.redhat.com/ |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
2
diff
changeset
|
18 // |
|
66
bf00f99aec69
Merge from eCos master repository on 2000-02-02-19:16:44-GMT
jlarmour
parents:
64
diff
changeset
|
19 // 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:
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-10 | |
| 40 // Purpose: Define multilevel queue scheduler implementation | |
| 41 // Description: The classes defined here are used as base classes | |
| 0 | 42 // by the common classes that define schedulers and thread |
| 43 // things. The MLQ scheduler in various configurations | |
| 44 // provides standard FIFO, round-robin and single priority | |
| 45 // schedulers. | |
| 46 // Usage: Included according to configuration by | |
| 47 // <cyg/kernel/sched.hxx> | |
| 48 // | |
| 49 //####DESCRIPTIONEND#### | |
| 50 // | |
| 51 //========================================================================== | |
| 52 | |
| 53 #include <cyg/kernel/ktypes.h> | |
| 54 | |
| 55 // ------------------------------------------------------------------------- | |
| 56 // The macro CYGNUM_KERNEL_SCHED_PRIORITIES contains the number of priorities | |
| 57 // supported by the scheduler. | |
| 58 | |
| 59 #ifndef CYGNUM_KERNEL_SCHED_PRIORITIES | |
| 60 #define CYGNUM_KERNEL_SCHED_PRIORITIES 32 // define a default | |
| 61 #endif | |
| 62 | |
| 63 // set bitmap size | |
| 64 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE CYGNUM_KERNEL_SCHED_PRIORITIES | |
| 65 | |
| 66 // ------------------------------------------------------------------------- | |
| 67 // The macro CYGNUM_KERNEL_SCHED_BITMAP_SIZE contains the number of bits that the | |
| 68 // scheduler bitmap should contain. It is derived from the number of prioirity | |
| 69 // levels defined by the configuration. | |
| 70 | |
| 71 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8 | |
| 72 typedef cyg_ucount8 cyg_sched_bitmap; | |
| 73 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16 | |
| 74 typedef cyg_ucount16 cyg_sched_bitmap; | |
| 75 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32 | |
| 76 typedef cyg_ucount32 cyg_sched_bitmap; | |
| 77 #else | |
| 78 #error Bitmaps greater than 32 bits not currently allowed | |
| 79 #endif | |
| 80 | |
| 81 // ------------------------------------------------------------------------- | |
| 82 // Customize the scheduler | |
| 83 | |
| 84 #define CYGIMP_THREAD_PRIORITY 1 // Threads have changable priorities | |
| 85 #define CYG_SCHED_UNIQUE_PRIORITIES 0 // Threads don't have unique priorities | |
| 86 | |
| 87 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES-1) | |
| 88 #define CYG_THREAD_MAX_PRIORITY 0 | |
| 89 | |
| 90 // set default scheduling info value for thread constructors. | |
| 91 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY | |
| 92 | |
| 93 // ------------------------------------------------------------------------- | |
| 94 // Thread queue implementation. | |
| 95 // This class provides the (scheduler specific) implementation of the | |
| 96 // thread queue class. | |
| 97 | |
| 98 class Cyg_ThreadQueue_Implementation | |
| 99 { | |
| 100 friend class Cyg_Scheduler_Implementation; | |
| 101 friend class Cyg_SchedThread_Implementation; | |
| 102 | |
| 103 Cyg_Thread *queue; | |
| 104 | |
| 105 protected: | |
| 106 | |
| 107 // API used by Cyg_ThreadQueue | |
| 108 | |
| 109 Cyg_ThreadQueue_Implementation(); // Constructor | |
| 110 | |
| 111 // Add thread to queue | |
| 112 void enqueue(Cyg_Thread *thread); | |
| 113 | |
| 114 // return first thread on queue | |
| 115 Cyg_Thread *highpri(); | |
| 116 | |
| 117 // remove first thread on queue | |
| 118 Cyg_Thread *dequeue(); | |
| 119 | |
| 120 // remove specified thread from queue | |
| 121 void remove(Cyg_Thread *thread); | |
| 122 | |
| 123 // test if queue is empty | |
| 124 cyg_bool empty(); | |
| 125 | |
| 126 void rotate(); // Rotate the queue | |
| 2 | 127 |
| 128 void to_head(Cyg_Thread *thread); | |
| 129 | |
| 0 | 130 }; |
| 131 | |
| 132 inline cyg_bool Cyg_ThreadQueue_Implementation::empty() | |
| 133 { | |
| 134 return queue == NULL; | |
| 135 } | |
| 136 | |
| 137 // ------------------------------------------------------------------------- | |
| 138 // This class contains the implementation details of the scheduler, and | |
| 139 // provides a standard API for accessing it. | |
| 140 | |
| 141 class Cyg_Scheduler_Implementation | |
| 142 : public Cyg_Scheduler_Base | |
| 143 { | |
| 144 friend class Cyg_ThreadQueue_Implementation; | |
| 145 friend class Cyg_SchedThread_Implementation; | |
| 146 friend class Cyg_HardwareThread; | |
| 147 | |
| 148 // Mask of which run queues have ready threads | |
| 149 cyg_sched_bitmap queue_map; | |
| 150 | |
| 151 // Each run queue is a double linked circular list of threads. | |
| 152 // These pointers point to the head element of each list. | |
| 153 Cyg_ThreadQueue_Implementation run_queue[CYGNUM_KERNEL_SCHED_PRIORITIES]; | |
| 154 | |
| 155 protected: | |
| 156 | |
| 157 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 158 | |
| 159 // Timeslice counter. This is decremented on each | |
| 160 // clock tick, and a timeslice is performed each | |
| 161 // time it zeroes. | |
| 162 | |
| 163 static cyg_ucount32 timeslice_count; | |
| 164 | |
| 165 static void reset_timeslice_count(); | |
| 166 | |
| 167 #endif | |
| 168 | |
| 169 Cyg_Scheduler_Implementation(); // Constructor | |
| 170 | |
| 171 // The following functions provide the scheduler implementation | |
| 172 // interface to the Cyg_Scheduler class. These are protected | |
| 173 // so that only the scheduler can call them. | |
| 174 | |
| 175 // choose a new thread | |
| 176 Cyg_Thread *schedule(); | |
| 177 | |
| 178 // make thread schedulable | |
| 179 void add_thread(Cyg_Thread *thread); | |
| 180 | |
| 181 // make thread un-schedulable | |
| 182 void rem_thread(Cyg_Thread *thread); | |
| 183 | |
| 184 // register thread with scheduler | |
| 185 void register_thread(Cyg_Thread *thread); | |
| 186 | |
| 187 // deregister thread | |
| 188 void deregister_thread(Cyg_Thread *thread); | |
| 189 | |
| 190 // Test the given priority for uniqueness | |
| 191 cyg_bool unique( cyg_priority priority); | |
| 192 | |
| 193 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 194 | |
| 195 // If timeslicing is enbled, define a scheduler | |
| 196 // entry point to do timeslicing. This will be | |
| 197 // called from the RTC DSR. | |
| 198 public: | |
| 199 void timeslice(); | |
| 200 | |
| 201 #endif | |
| 202 | |
| 203 }; | |
| 204 | |
| 205 // ------------------------------------------------------------------------- | |
| 206 // Cyg_Scheduler_Implementation inlines | |
| 207 | |
| 208 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 209 | |
| 210 inline void Cyg_Scheduler_Implementation::reset_timeslice_count() | |
| 211 { | |
| 212 timeslice_count = CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS; | |
| 213 } | |
| 214 | |
| 215 #endif | |
| 216 | |
| 217 // ------------------------------------------------------------------------- | |
| 218 // Scheduler thread implementation. | |
| 219 // This class provides the implementation of the scheduler specific parts | |
| 220 // of each thread. | |
| 221 | |
| 222 class Cyg_SchedThread_Implementation | |
| 223 { | |
| 224 friend class Cyg_Scheduler_Implementation; | |
| 225 friend class Cyg_ThreadQueue_Implementation; | |
| 226 | |
| 227 Cyg_Thread *next; // next thread in queue | |
| 228 Cyg_Thread *prev; // previous thread in queue | |
| 229 | |
| 230 void insert( Cyg_Thread *thread ); // Insert thread in front of this | |
| 231 | |
| 232 void remove(); // remove this from queue | |
| 233 | |
| 234 protected: | |
| 235 | |
| 236 cyg_priority priority; // current thread priority | |
| 237 | |
| 238 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info); | |
| 239 | |
| 240 void yield(); // Yield CPU to next thread | |
| 241 | |
| 242 static void rotate_queue( cyg_priority pri ); | |
| 243 // Rotate that run queue | |
| 2 | 244 |
| 245 void to_queue_head( void ); // Move this thread to the head | |
| 246 // of its queue (not necessarily | |
| 247 // a scheduler queue) | |
| 0 | 248 }; |
| 249 | |
| 250 // ------------------------------------------------------------------------- | |
| 251 #endif // ifndef CYGONCE_KERNEL_MLQUEUE_HXX | |
| 252 // EOF mlqueue.hxx |
