Mercurial > flash_v2
annotate packages/kernel/current/include/sched.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_SCHED_HXX |
| 2 #define CYGONCE_KERNEL_SCHED_HXX | |
| 3 | |
| 4 //========================================================================== | |
| 5 // | |
| 2 | 6 // sched.hxx |
| 0 | 7 // |
| 2 | 8 // Scheduler class declaration(s) |
| 0 | 9 // |
| 10 //========================================================================== | |
| 11 //####COPYRIGHTBEGIN#### | |
|
64
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
12 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
13 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
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:
62
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:
62
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:
62
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:
62
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:
62
diff
changeset
|
22 // the License. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
23 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
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:
62
diff
changeset
|
25 // released September 30, 1998. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
26 // |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
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:
62
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:
62
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:
62
diff
changeset
|
30 // All Rights Reserved. |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
31 // ------------------------------------------- |
|
c38311975d4f
Merge from eCos master repository on 2000-01-28-04:28:11-GMT
jlarmour
parents:
62
diff
changeset
|
32 // |
| 0 | 33 //####COPYRIGHTEND#### |
| 34 //========================================================================== | |
| 35 //#####DESCRIPTIONBEGIN#### | |
| 36 // | |
| 2 | 37 // Author(s): nickg |
| 38 // Contributors: nickg | |
| 39 // Date: 1997-09-09 | |
| 40 // Purpose: Define Scheduler class interfaces | |
| 41 // Description: These class definitions supply the internal API | |
| 0 | 42 // used to scheduler threads. |
| 2 | 43 // Usage: #include <cyg/kernel/sched.hxx> |
| 0 | 44 // |
| 45 //####DESCRIPTIONEND#### | |
| 46 // | |
| 47 //========================================================================== | |
| 48 | |
| 49 #include <cyg/kernel/ktypes.h> | |
| 50 #include <cyg/infra/cyg_ass.h> // assertion macros | |
| 51 | |
| 52 // ------------------------------------------------------------------------- | |
| 53 // Scheduler base class. This defines stuff that is needed by the | |
| 54 // specific scheduler implementation. Each scheduler comprises three | |
| 55 // classes: Cyg_Scheduler_Base, Cyg_Scheduler_Implementation which | |
| 56 // inherits from it and Cyg_Scheduler which inherits from _it_ in turn. | |
| 57 | |
| 58 class Cyg_Scheduler_Base | |
| 59 { | |
| 60 friend class Cyg_HardwareThread; | |
| 61 friend class Cyg_SchedThread; | |
| 62 | |
| 63 protected: | |
| 64 // The following variables are implicit in the API, but are | |
| 65 // not publically visible. | |
| 66 | |
| 2 | 67 static volatile cyg_ucount32 sched_lock // lock counter |
| 68 CYGBLD_ATTRIB_ASM_ALIAS( cyg_scheduler_sched_lock ); | |
| 69 | |
| 0 | 70 static Cyg_Thread *current_thread; // current running thread |
| 71 | |
| 72 static cyg_bool need_reschedule; // set when schedule needed | |
| 73 | |
| 74 static cyg_ucount32 thread_switches; // count of number of thread switches | |
| 75 }; | |
| 76 | |
| 77 // ------------------------------------------------------------------------- | |
| 78 // Include the scheduler implementation header | |
| 79 | |
| 80 #include CYGPRI_KERNEL_SCHED_IMPL_HXX | |
| 81 | |
| 82 // Do some checking that we have a consistent universe. | |
| 83 | |
| 84 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | |
| 85 # ifndef CYGIMP_THREAD_PRIORITY | |
| 86 # error Priority inheritance will not work without priorities!!! | |
| 87 # endif | |
| 88 # if CYG_SCHED_UNIQUE_PRIORITIES | |
| 89 # error Priority inheritance needs non-unique priorities!!! | |
| 90 # endif | |
| 91 #endif | |
| 92 | |
| 93 // ------------------------------------------------------------------------- | |
| 94 // Scheduler class. This is the public scheduler interface seen by the | |
| 95 // rest of the kernel. | |
| 96 | |
| 97 class Cyg_Scheduler | |
| 98 : public Cyg_Scheduler_Implementation | |
| 99 { | |
| 100 friend class Cyg_Thread; | |
| 101 | |
| 102 // This function is the actual implementation of the unlock | |
| 103 // function. The unlock() later is an inline shell that deals | |
| 104 // with the common case. | |
| 105 | |
| 106 static void unlock_inner(); | |
| 107 | |
| 108 public: | |
| 109 | |
| 110 CYGDBG_DEFINE_CHECK_THIS | |
| 111 | |
| 112 // The following API functions are common to all scheduler | |
| 113 // implementations. | |
| 114 | |
| 115 // claim the preemption lock | |
| 116 static void lock(); | |
| 117 | |
| 2 | 118 // release the preemption lock and possibly reschedule |
| 0 | 119 static void unlock(); |
| 120 | |
| 2 | 121 // release the preemption lock without rescheduling |
| 122 static void unlock_simple(); | |
| 123 | |
| 0 | 124 // return a pointer to the current thread |
| 125 static Cyg_Thread *get_current_thread(); | |
| 126 | |
| 127 // Return current value of lock | |
| 128 static cyg_ucount32 get_sched_lock(); | |
| 129 | |
| 130 // Return current number of thread switches | |
| 131 static cyg_ucount32 get_thread_switches(); | |
| 132 | |
| 133 // Start execution of the scheduler | |
| 134 static void start() __attribute__ ((noreturn)); | |
| 135 | |
| 136 // The only scheduler instance should be this one... | |
| 137 static Cyg_Scheduler scheduler; | |
| 138 | |
| 139 }; | |
| 140 | |
| 141 // ------------------------------------------------------------------------- | |
| 142 // This class encapsulates the scheduling abstractions in a thread. | |
| 143 // Cyg_SchedThread is included as a base class of Cyg_Thread. The actual | |
| 144 // implementation of the abstractions is in Cyg_SchedThread_Implementation | |
| 145 // so this class has little to do. | |
| 146 | |
| 147 class Cyg_SchedThread | |
| 148 : public Cyg_SchedThread_Implementation | |
| 149 { | |
| 150 friend class Cyg_ThreadQueue_Implementation; | |
| 151 friend class Cyg_Scheduler_Implementation; | |
| 152 | |
| 153 Cyg_ThreadQueue *queue; | |
| 154 | |
| 155 | |
| 156 public: | |
| 157 | |
| 158 Cyg_SchedThread(Cyg_Thread *thread, CYG_ADDRWORD sched_info); | |
| 159 | |
| 160 // Return current queue pointer | |
| 161 | |
| 162 Cyg_ThreadQueue *get_current_queue(); | |
| 163 | |
| 164 // Remove this thread from current queue | |
| 165 void remove(); | |
| 166 | |
| 167 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | |
| 168 | |
| 169 private: | |
| 170 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
171 // For all priority inheritance mechanisms we need to keep track of how |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
172 // many mutexes we have locked, including one which we are waiting to |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
173 // lock, because we can inherit priority while sleeping just prior to |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
174 // wakeup. |
| 0 | 175 cyg_count32 mutex_count; |
| 176 | |
| 177 public: | |
| 178 // Count and uncount the number of mutexes held by | |
| 179 // this thread. | |
| 180 void count_mutex() { mutex_count++; }; | |
| 181 void uncount_mutex() { mutex_count--; }; | |
| 182 | |
| 183 protected: | |
| 184 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | |
| 185 | |
| 186 // The simple priority inheritance mechanism simply needs | |
| 187 // somewhere to store the base priority of the current thread. | |
| 188 | |
| 189 cyg_priority original_priority; // our original priority | |
| 190 | |
| 191 cyg_bool priority_inherited; // have we inherited? | |
| 192 | |
| 193 #endif | |
| 194 | |
| 195 public: | |
| 196 | |
| 197 // Inherit the priority of the provided thread if it | |
| 198 // has higher priority than this. | |
| 199 void inherit_priority( Cyg_Thread *thread); | |
| 200 | |
|
62
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
201 // Relay the priority of the ex-owner thread or from the queue if it |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
202 // has a higher priority than ours. |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
203 void relay_priority( Cyg_Thread *ex_owner, Cyg_ThreadQueue *pqueue); |
|
7a6ac9edc838
Merge from eCos master repository on 2000-01-24-19:43:49-GMT
jlarmour
parents:
2
diff
changeset
|
204 |
| 0 | 205 // Lose priority inheritance |
| 206 void disinherit_priority(); | |
| 207 | |
| 208 #endif | |
| 209 | |
| 210 }; | |
| 211 | |
| 212 // ------------------------------------------------------------------------- | |
| 213 // Simple inline accessor functions | |
| 214 | |
| 215 inline Cyg_Thread *Cyg_Scheduler::get_current_thread() | |
| 216 { | |
| 217 return current_thread; | |
| 218 } | |
| 219 | |
| 220 // Return current value of lock | |
| 221 inline cyg_ucount32 Cyg_Scheduler::get_sched_lock() | |
| 222 { | |
| 223 return sched_lock; | |
| 224 } | |
| 225 | |
| 226 // Return current number of thread switches | |
| 227 inline cyg_ucount32 Cyg_Scheduler::get_thread_switches() | |
| 228 { | |
| 229 return thread_switches; | |
| 230 } | |
| 231 | |
| 232 // Return current queue pointer | |
| 233 inline Cyg_ThreadQueue *Cyg_SchedThread::get_current_queue() | |
| 234 { | |
| 235 return queue; | |
| 236 } | |
| 237 | |
| 238 // ------------------------------------------------------------------------- | |
| 239 #endif // ifndef __SCHED_HXX__ | |
| 240 // EOF sched.hxx |
