Mercurial > flash_v2
comparison packages/kernel/current/include/mlqueue.hxx @ 0:3111d98ba7b3 ecos-v1_1-release
Initial commit of eCos version 1.1
| author | jlarmour |
|---|---|
| date | Tue, 11 May 1999 11:16:07 +0000 |
| parents | |
| children | 443894e2e912 |
comparison
equal
deleted
inserted
replaced
| -1:000000000000 | 0:3111d98ba7b3 |
|---|---|
| 1 #ifndef CYGONCE_KERNEL_MLQUEUE_HXX | |
| 2 #define CYGONCE_KERNEL_MLQUEUE_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 6 // mlqueue.hxx | |
| 7 // | |
| 8 // Multi-Level Queue scheduler class declarations | |
| 9 // | |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
| 12 // | |
| 13 // ------------------------------------------- | |
| 14 // The contents of this file are subject to the Cygnus eCos Public License | |
| 15 // Version 1.0 (the "License"); you may not use this file except in | |
| 16 // compliance with the License. You may obtain a copy of the License at | |
| 17 // http://sourceware.cygnus.com/ecos | |
| 18 // | |
| 19 // Software distributed under the License is distributed on an "AS IS" | |
| 20 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the | |
| 21 // License for the specific language governing rights and limitations under | |
| 22 // the License. | |
| 23 // | |
| 24 // The Original Code is eCos - Embedded Cygnus Operating System, released | |
| 25 // September 30, 1998. | |
| 26 // | |
| 27 // The Initial Developer of the Original Code is Cygnus. Portions created | |
| 28 // by Cygnus are Copyright (C) 1998 Cygnus Solutions. All Rights Reserved. | |
| 29 // ------------------------------------------- | |
| 30 // | |
| 31 //####COPYRIGHTEND#### | |
| 32 //========================================================================== | |
| 33 //#####DESCRIPTIONBEGIN#### | |
| 34 // | |
| 35 // Author(s): nickg | |
| 36 // Contributors: nickg | |
| 37 // Date: 1997-09-10 | |
| 38 // Purpose: Define multilevel queue scheduler implementation | |
| 39 // Description: The classes defined here are used as base classes | |
| 40 // by the common classes that define schedulers and thread | |
| 41 // things. The MLQ scheduler in various configurations | |
| 42 // provides standard FIFO, round-robin and single priority | |
| 43 // schedulers. | |
| 44 // Usage: Included according to configuration by | |
| 45 // <cyg/kernel/sched.hxx> | |
| 46 // | |
| 47 //####DESCRIPTIONEND#### | |
| 48 // | |
| 49 //========================================================================== | |
| 50 | |
| 51 #include <cyg/kernel/ktypes.h> | |
| 52 | |
| 53 // ------------------------------------------------------------------------- | |
| 54 // The macro CYGNUM_KERNEL_SCHED_PRIORITIES contains the number of priorities | |
| 55 // supported by the scheduler. | |
| 56 | |
| 57 #ifndef CYGNUM_KERNEL_SCHED_PRIORITIES | |
| 58 #define CYGNUM_KERNEL_SCHED_PRIORITIES 32 // define a default | |
| 59 #endif | |
| 60 | |
| 61 // set bitmap size | |
| 62 #define CYGNUM_KERNEL_SCHED_BITMAP_SIZE CYGNUM_KERNEL_SCHED_PRIORITIES | |
| 63 | |
| 64 // ------------------------------------------------------------------------- | |
| 65 // The macro CYGNUM_KERNEL_SCHED_BITMAP_SIZE contains the number of bits that the | |
| 66 // scheduler bitmap should contain. It is derived from the number of prioirity | |
| 67 // levels defined by the configuration. | |
| 68 | |
| 69 #if CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 8 | |
| 70 typedef cyg_ucount8 cyg_sched_bitmap; | |
| 71 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 16 | |
| 72 typedef cyg_ucount16 cyg_sched_bitmap; | |
| 73 #elif CYGNUM_KERNEL_SCHED_BITMAP_SIZE <= 32 | |
| 74 typedef cyg_ucount32 cyg_sched_bitmap; | |
| 75 #else | |
| 76 #error Bitmaps greater than 32 bits not currently allowed | |
| 77 #endif | |
| 78 | |
| 79 // ------------------------------------------------------------------------- | |
| 80 // Customize the scheduler | |
| 81 | |
| 82 #define CYGIMP_THREAD_PRIORITY 1 // Threads have changable priorities | |
| 83 #define CYG_SCHED_UNIQUE_PRIORITIES 0 // Threads don't have unique priorities | |
| 84 | |
| 85 #define CYG_THREAD_MIN_PRIORITY (CYGNUM_KERNEL_SCHED_PRIORITIES-1) | |
| 86 #define CYG_THREAD_MAX_PRIORITY 0 | |
| 87 | |
| 88 // set default scheduling info value for thread constructors. | |
| 89 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY | |
| 90 | |
| 91 // ------------------------------------------------------------------------- | |
| 92 // Thread queue implementation. | |
| 93 // This class provides the (scheduler specific) implementation of the | |
| 94 // thread queue class. | |
| 95 | |
| 96 class Cyg_ThreadQueue_Implementation | |
| 97 { | |
| 98 friend class Cyg_Scheduler_Implementation; | |
| 99 friend class Cyg_SchedThread_Implementation; | |
| 100 | |
| 101 Cyg_Thread *queue; | |
| 102 | |
| 103 protected: | |
| 104 | |
| 105 // API used by Cyg_ThreadQueue | |
| 106 | |
| 107 Cyg_ThreadQueue_Implementation(); // Constructor | |
| 108 | |
| 109 // Add thread to queue | |
| 110 void enqueue(Cyg_Thread *thread); | |
| 111 | |
| 112 // return first thread on queue | |
| 113 Cyg_Thread *highpri(); | |
| 114 | |
| 115 // remove first thread on queue | |
| 116 Cyg_Thread *dequeue(); | |
| 117 | |
| 118 // remove specified thread from queue | |
| 119 void remove(Cyg_Thread *thread); | |
| 120 | |
| 121 // test if queue is empty | |
| 122 cyg_bool empty(); | |
| 123 | |
| 124 void rotate(); // Rotate the queue | |
| 125 }; | |
| 126 | |
| 127 inline cyg_bool Cyg_ThreadQueue_Implementation::empty() | |
| 128 { | |
| 129 return queue == NULL; | |
| 130 } | |
| 131 | |
| 132 // ------------------------------------------------------------------------- | |
| 133 // This class contains the implementation details of the scheduler, and | |
| 134 // provides a standard API for accessing it. | |
| 135 | |
| 136 class Cyg_Scheduler_Implementation | |
| 137 : public Cyg_Scheduler_Base | |
| 138 { | |
| 139 friend class Cyg_ThreadQueue_Implementation; | |
| 140 friend class Cyg_SchedThread_Implementation; | |
| 141 friend class Cyg_HardwareThread; | |
| 142 | |
| 143 // Mask of which run queues have ready threads | |
| 144 cyg_sched_bitmap queue_map; | |
| 145 | |
| 146 // Each run queue is a double linked circular list of threads. | |
| 147 // These pointers point to the head element of each list. | |
| 148 Cyg_ThreadQueue_Implementation run_queue[CYGNUM_KERNEL_SCHED_PRIORITIES]; | |
| 149 | |
| 150 protected: | |
| 151 | |
| 152 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 153 | |
| 154 // Timeslice counter. This is decremented on each | |
| 155 // clock tick, and a timeslice is performed each | |
| 156 // time it zeroes. | |
| 157 | |
| 158 static cyg_ucount32 timeslice_count; | |
| 159 | |
| 160 static void reset_timeslice_count(); | |
| 161 | |
| 162 #endif | |
| 163 | |
| 164 Cyg_Scheduler_Implementation(); // Constructor | |
| 165 | |
| 166 // The following functions provide the scheduler implementation | |
| 167 // interface to the Cyg_Scheduler class. These are protected | |
| 168 // so that only the scheduler can call them. | |
| 169 | |
| 170 // choose a new thread | |
| 171 Cyg_Thread *schedule(); | |
| 172 | |
| 173 // make thread schedulable | |
| 174 void add_thread(Cyg_Thread *thread); | |
| 175 | |
| 176 // make thread un-schedulable | |
| 177 void rem_thread(Cyg_Thread *thread); | |
| 178 | |
| 179 // register thread with scheduler | |
| 180 void register_thread(Cyg_Thread *thread); | |
| 181 | |
| 182 // deregister thread | |
| 183 void deregister_thread(Cyg_Thread *thread); | |
| 184 | |
| 185 // Test the given priority for uniqueness | |
| 186 cyg_bool unique( cyg_priority priority); | |
| 187 | |
| 188 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 189 | |
| 190 // If timeslicing is enbled, define a scheduler | |
| 191 // entry point to do timeslicing. This will be | |
| 192 // called from the RTC DSR. | |
| 193 public: | |
| 194 void timeslice(); | |
| 195 | |
| 196 #endif | |
| 197 | |
| 198 }; | |
| 199 | |
| 200 // ------------------------------------------------------------------------- | |
| 201 // Cyg_Scheduler_Implementation inlines | |
| 202 | |
| 203 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 204 | |
| 205 inline void Cyg_Scheduler_Implementation::reset_timeslice_count() | |
| 206 { | |
| 207 timeslice_count = CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS; | |
| 208 } | |
| 209 | |
| 210 #endif | |
| 211 | |
| 212 // ------------------------------------------------------------------------- | |
| 213 // Scheduler thread implementation. | |
| 214 // This class provides the implementation of the scheduler specific parts | |
| 215 // of each thread. | |
| 216 | |
| 217 class Cyg_SchedThread_Implementation | |
| 218 { | |
| 219 friend class Cyg_Scheduler_Implementation; | |
| 220 friend class Cyg_ThreadQueue_Implementation; | |
| 221 | |
| 222 Cyg_Thread *next; // next thread in queue | |
| 223 Cyg_Thread *prev; // previous thread in queue | |
| 224 | |
| 225 void insert( Cyg_Thread *thread ); // Insert thread in front of this | |
| 226 | |
| 227 void remove(); // remove this from queue | |
| 228 | |
| 229 protected: | |
| 230 | |
| 231 cyg_priority priority; // current thread priority | |
| 232 | |
| 233 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info); | |
| 234 | |
| 235 void yield(); // Yield CPU to next thread | |
| 236 | |
| 237 static void rotate_queue( cyg_priority pri ); | |
| 238 // Rotate that run queue | |
| 239 }; | |
| 240 | |
| 241 // ------------------------------------------------------------------------- | |
| 242 #endif // ifndef CYGONCE_KERNEL_MLQUEUE_HXX | |
| 243 // EOF mlqueue.hxx |
