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