Mercurial > flash_v2
annotate packages/kernel/current/include/lottery.hxx @ 210:d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
| author | jlarmour |
|---|---|
| date | Thu, 23 May 2002 22:59:51 +0000 |
| parents | e0c0827131d1 |
| children |
| rev | line source |
|---|---|
| 0 | 1 #ifndef CYGONCE_KERNEL_LOTTERY_HXX |
| 2 #define CYGONCE_KERNEL_LOTTERY_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // lottery.hxx |
| 0 | 7 // |
| 2 | 8 // Lottery scheduler class declarations |
| 0 | 9 // |
| 10 //========================================================================== | |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
11 //####ECOSGPLCOPYRIGHTBEGIN#### |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
12 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
13 // This file is part of eCos, the Embedded Configurable Operating System. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
14 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
15 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
16 // eCos is free software; you can redistribute it and/or modify it under |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
17 // the terms of the GNU General Public License as published by the Free |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
18 // Software Foundation; either version 2 or (at your option) any later version. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
19 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
20 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
21 // WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
22 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
23 // for more details. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
24 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
25 // You should have received a copy of the GNU General Public License along |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
26 // with eCos; if not, write to the Free Software Foundation, Inc., |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
27 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
28 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
29 // As a special exception, if other files instantiate templates or use macros |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
30 // or inline functions from this file, or you compile this file and link it |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
31 // with other works to produce a work based on this file, this file does not |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
32 // by itself cause the resulting work to be covered by the GNU General Public |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
33 // License. However the source code for this file must still be made available |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
34 // in accordance with section (3) of the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
35 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
36 // This exception does not invalidate any other reasons why a work based on |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
37 // this file might be covered by the GNU General Public License. |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
38 // |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
39 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc. |
|
210
d2c90368aeef
Merge from eCos master repository on 2002-05-23-21:39:14-BST
jlarmour
parents:
208
diff
changeset
|
40 // at http://sources.redhat.com/ecos/ecos-license/ |
|
208
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
41 // ------------------------------------------- |
|
e0c0827131d1
Merge from eCos master repository on 2002-05-20-20:11:54-BST
jlarmour
parents:
66
diff
changeset
|
42 //####ECOSGPLCOPYRIGHTEND#### |
| 0 | 43 //========================================================================== |
| 44 //#####DESCRIPTIONBEGIN#### | |
| 45 // | |
| 2 | 46 // Author(s): nickg |
| 47 // Contributors: nickg | |
| 48 // Date: 1997-09-10 | |
| 49 // Purpose: Define lottery scheduler implementation | |
| 50 // Description: The classes defined here are used as base classes | |
| 0 | 51 // by the common classes that define schedulers and thread |
| 52 // things. A lottery scheduler provides each thread with a | |
| 53 // share of the processor based on the number of tickets that | |
| 54 // it owns. | |
| 55 // Usage: Included according to configuration by | |
| 56 // <cyg/kernel/sched.hxx> | |
| 57 // | |
| 58 //####DESCRIPTIONEND#### | |
| 59 // | |
| 60 //========================================================================== | |
| 61 | |
| 62 #include <cyg/kernel/ktypes.h> | |
| 63 | |
| 64 // ------------------------------------------------------------------------- | |
| 65 // Customize the scheduler | |
| 66 | |
| 67 #define CYGIMP_THREAD_PRIORITY 1 // Threads have changable priorities | |
| 68 | |
| 69 #define CYG_THREAD_MIN_PRIORITY 1 | |
| 70 #define CYG_THREAD_MAX_PRIORITY 0x7FFFFFFF | |
| 71 | |
| 72 // set default scheduling info value for thread constructors. | |
| 73 #define CYG_SCHED_DEFAULT_INFO CYG_THREAD_MAX_PRIORITY | |
| 74 | |
| 75 #error Lottery Scheduler not yet complete, do not use!!! | |
| 76 | |
| 77 // ------------------------------------------------------------------------- | |
| 78 // Thread queue implementation. | |
| 79 // This class provides the (scheduler specific) implementation of the | |
| 80 // thread queue class. | |
| 81 | |
| 82 class Cyg_ThreadQueue_Implementation | |
| 83 { | |
| 84 friend class Cyg_Scheduler_Implementation; | |
| 85 friend class Cyg_SchedThread_Implementation; | |
| 86 | |
| 87 Cyg_Thread *queue; | |
| 88 | |
| 89 protected: | |
| 90 | |
| 91 // API used by Cyg_ThreadQueue | |
| 92 | |
| 93 // Add thread to queue | |
| 94 void enqueue(Cyg_Thread *thread); | |
| 95 | |
| 96 // return first thread on queue | |
| 97 Cyg_Thread *highpri(); | |
| 98 | |
| 99 // remove first thread on queue | |
| 100 Cyg_Thread *dequeue(); | |
| 101 | |
| 102 // remove specified thread from queue | |
| 103 void remove(Cyg_Thread *thread); | |
| 104 | |
| 105 // test if queue is empty | |
| 106 cyg_bool empty(); | |
| 107 | |
| 108 void rotate(); // Rotate the queue | |
| 109 }; | |
| 110 | |
| 111 inline cyg_bool Cyg_ThreadQueue_Implementation::empty() | |
| 112 { | |
| 113 return queue == NULL; | |
| 114 } | |
| 115 | |
| 116 // ------------------------------------------------------------------------- | |
| 117 // This class contains the implementation details of the scheduler, and | |
| 118 // provides a standard API for accessing it. | |
| 119 | |
| 120 class Cyg_Scheduler_Implementation | |
| 121 : public Cyg_Scheduler_Base | |
| 122 { | |
| 123 friend class Cyg_ThreadQueue_Implementation; | |
| 124 friend class Cyg_SchedThread_Implementation; | |
| 125 | |
| 126 // All runnable threads are kept on a single run queue | |
| 127 // in MRU order. | |
| 128 Cyg_ThreadQueue_Implementation run_queue; | |
| 129 | |
| 130 cyg_uint32 rand_seed; | |
| 131 | |
| 132 cyg_int32 total_tickets; | |
| 133 | |
| 134 protected: | |
| 135 | |
| 136 Cyg_Scheduler_Implementation(); // Constructor | |
| 137 | |
| 138 // The following functions provide the scheduler implementation | |
| 139 // interface to the Cyg_Scheduler class. These are protected | |
| 140 // so that only the scheduler can call them. | |
| 141 | |
| 142 // choose a new thread | |
| 143 Cyg_Thread *schedule(); | |
| 144 | |
| 145 // make thread schedulable | |
| 146 void add_thread(Cyg_Thread *thread); | |
| 147 | |
| 148 // make thread un-schedulable | |
| 149 void rem_thread(Cyg_Thread *thread); | |
| 150 | |
| 151 // register thread with scheduler | |
| 152 void register_thread(Cyg_Thread *thread); | |
| 153 | |
| 154 // deregister thread | |
| 155 void deregister_thread(Cyg_Thread *thread); | |
| 156 | |
| 157 // Test the given priority for uniqueness | |
| 158 cyg_bool unique( cyg_priority priority); | |
| 159 | |
| 160 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 161 | |
| 162 // If timeslicing is enbled, define a scheduler | |
| 163 // entry point to do timeslicing. This will be | |
| 164 // called from the RTC DSR. | |
| 165 | |
| 166 protected: | |
| 167 | |
| 168 static cyg_count32 timeslice_count; | |
| 169 | |
| 170 public: | |
| 171 void timeslice(); | |
| 172 | |
| 173 static void reset_timeslice_count(); | |
| 174 | |
| 175 #endif | |
| 176 | |
| 177 | |
| 178 }; | |
| 179 | |
| 180 // ------------------------------------------------------------------------- | |
| 181 // Cyg_Scheduler_Implementation inlines | |
| 182 | |
| 183 #ifdef CYGSEM_KERNEL_SCHED_TIMESLICE | |
| 184 | |
| 185 inline void Cyg_Scheduler_Implementation::reset_timeslice_count() | |
| 186 { | |
| 187 timeslice_count = CYGNUM_KERNEL_SCHED_TIMESLICE_TICKS; | |
| 188 } | |
| 189 | |
| 190 #endif | |
| 191 | |
| 192 // ------------------------------------------------------------------------- | |
| 193 // Scheduler thread implementation. | |
| 194 // This class provides the implementation of the scheduler specific parts | |
| 195 // of each thread. | |
| 196 | |
| 197 class Cyg_SchedThread_Implementation | |
| 198 { | |
| 199 friend class Cyg_Scheduler_Implementation; | |
| 200 friend class Cyg_ThreadQueue_Implementation; | |
| 201 | |
| 202 Cyg_Thread *next; // next thread in queue | |
| 203 Cyg_Thread *prev; // previous thread in queue | |
| 204 | |
| 205 void insert( Cyg_Thread *thread ); // Insert thread in front of this | |
| 206 | |
| 207 void remove(); // remove this from queue | |
| 208 | |
| 209 protected: | |
| 210 | |
| 211 cyg_priority priority; // current thread priority == tickets held | |
| 212 | |
| 213 cyg_priority compensation_tickets; // sleep compensation | |
| 214 | |
| 215 Cyg_SchedThread_Implementation(CYG_ADDRWORD sched_info); | |
| 216 | |
| 217 void yield(); // Yield CPU to next thread | |
| 218 | |
| 219 }; | |
| 220 | |
| 221 // ------------------------------------------------------------------------- | |
| 222 #endif // ifndef CYGONCE_KERNEL_LOTTERY_HXX | |
| 223 // EOF lottery.hxx |
