Mercurial > flash_v2
comparison packages/kernel/current/include/sched.hxx @ 115:6ed91473a1cd ecos-sw-2000-08-21
Merge from eCos master repository on 2000-08-21-22:40:54-BST
| author | jlarmour |
|---|---|
| date | Fri, 25 Aug 2000 17:32:38 +0000 |
| parents | bf00f99aec69 |
| children | 0ec04793409a |
comparison
equal
deleted
inserted
replaced
| 114:5ad2b71d525e | 115:6ed91473a1cd |
|---|---|
| 47 //========================================================================== | 47 //========================================================================== |
| 48 | 48 |
| 49 #include <cyg/kernel/ktypes.h> | 49 #include <cyg/kernel/ktypes.h> |
| 50 #include <cyg/infra/cyg_ass.h> // assertion macros | 50 #include <cyg/infra/cyg_ass.h> // assertion macros |
| 51 | 51 |
| 52 | |
| 53 // ------------------------------------------------------------------------- | |
| 54 // Miscellaneous types | |
| 55 | |
| 56 #ifdef CYGSEM_KERNEL_SCHED_ASR_SUPPORT | |
| 57 | |
| 58 typedef void Cyg_ASR( CYG_ADDRWORD data ); // ASR type signature | |
| 59 | |
| 60 #endif | |
| 61 | |
| 52 // ------------------------------------------------------------------------- | 62 // ------------------------------------------------------------------------- |
| 53 // Scheduler base class. This defines stuff that is needed by the | 63 // Scheduler base class. This defines stuff that is needed by the |
| 54 // specific scheduler implementation. Each scheduler comprises three | 64 // specific scheduler implementation. Each scheduler comprises three |
| 55 // classes: Cyg_Scheduler_Base, Cyg_Scheduler_Implementation which | 65 // classes: Cyg_Scheduler_Base, Cyg_Scheduler_Implementation which |
| 56 // inherits from it and Cyg_Scheduler which inherits from _it_ in turn. | 66 // inherits from it and Cyg_Scheduler which inherits from _it_ in turn. |
| 79 | 89 |
| 80 #include CYGPRI_KERNEL_SCHED_IMPL_HXX | 90 #include CYGPRI_KERNEL_SCHED_IMPL_HXX |
| 81 | 91 |
| 82 // Do some checking that we have a consistent universe. | 92 // Do some checking that we have a consistent universe. |
| 83 | 93 |
| 84 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | 94 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL |
| 85 # ifndef CYGIMP_THREAD_PRIORITY | 95 # ifndef CYGIMP_THREAD_PRIORITY |
| 86 # error Priority inheritance will not work without priorities!!! | 96 # error Priority inversion protocols will not work without priorities!!! |
| 87 # endif | 97 # endif |
| 88 # if CYG_SCHED_UNIQUE_PRIORITIES | 98 # if CYG_SCHED_UNIQUE_PRIORITIES |
| 89 # error Priority inheritance needs non-unique priorities!!! | 99 # error Priority inversion protocols need non-unique priorities!!! |
| 90 # endif | 100 # endif |
| 91 #endif | 101 #endif |
| 92 | 102 |
| 93 // ------------------------------------------------------------------------- | 103 // ------------------------------------------------------------------------- |
| 94 // Scheduler class. This is the public scheduler interface seen by the | 104 // Scheduler class. This is the public scheduler interface seen by the |
| 101 | 111 |
| 102 // This function is the actual implementation of the unlock | 112 // This function is the actual implementation of the unlock |
| 103 // function. The unlock() later is an inline shell that deals | 113 // function. The unlock() later is an inline shell that deals |
| 104 // with the common case. | 114 // with the common case. |
| 105 | 115 |
| 106 static void unlock_inner(); | 116 static void unlock_inner(cyg_uint32 new_lock = 0); |
| 107 | 117 |
| 108 public: | 118 public: |
| 109 | 119 |
| 110 CYGDBG_DEFINE_CHECK_THIS | 120 CYGDBG_DEFINE_CHECK_THIS |
| 111 | 121 |
| 116 static void lock(); | 126 static void lock(); |
| 117 | 127 |
| 118 // release the preemption lock and possibly reschedule | 128 // release the preemption lock and possibly reschedule |
| 119 static void unlock(); | 129 static void unlock(); |
| 120 | 130 |
| 131 // release and reclaim the lock atomically | |
| 132 static void reschedule(); | |
| 133 | |
| 121 // release the preemption lock without rescheduling | 134 // release the preemption lock without rescheduling |
| 122 static void unlock_simple(); | 135 static void unlock_simple(); |
| 123 | 136 |
| 124 // return a pointer to the current thread | 137 // return a pointer to the current thread |
| 125 static Cyg_Thread *get_current_thread(); | 138 static Cyg_Thread *get_current_thread(); |
| 147 class Cyg_SchedThread | 160 class Cyg_SchedThread |
| 148 : public Cyg_SchedThread_Implementation | 161 : public Cyg_SchedThread_Implementation |
| 149 { | 162 { |
| 150 friend class Cyg_ThreadQueue_Implementation; | 163 friend class Cyg_ThreadQueue_Implementation; |
| 151 friend class Cyg_Scheduler_Implementation; | 164 friend class Cyg_Scheduler_Implementation; |
| 165 friend class Cyg_Scheduler; | |
| 152 | 166 |
| 153 Cyg_ThreadQueue *queue; | 167 Cyg_ThreadQueue *queue; |
| 154 | 168 |
| 155 | 169 |
| 156 public: | 170 public: |
| 162 Cyg_ThreadQueue *get_current_queue(); | 176 Cyg_ThreadQueue *get_current_queue(); |
| 163 | 177 |
| 164 // Remove this thread from current queue | 178 // Remove this thread from current queue |
| 165 void remove(); | 179 void remove(); |
| 166 | 180 |
| 167 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE | 181 #ifdef CYGSEM_KERNEL_SCHED_ASR_SUPPORT |
| 182 | |
| 183 // ASR support. | |
| 184 // An ASR is an Asynchronous Service Routine. When set pending it | |
| 185 // is called when the thread exits the scheduler. ASRs are mainly | |
| 186 // used by compatibility subsystems, such as POSIX, to implement | |
| 187 // such things as thread cancellation and signal delivery. | |
| 168 | 188 |
| 169 private: | 189 private: |
| 170 | 190 |
| 171 // For all priority inheritance mechanisms we need to keep track of how | 191 volatile cyg_bool asr_inhibit; // If true, blocks calls to ASRs |
| 192 | |
| 193 volatile cyg_bool asr_pending; // If true, this thread's ASR should be called. | |
| 194 | |
| 195 #ifdef CYGSEM_KERNEL_SCHED_ASR_GLOBAL | |
| 196 static | |
| 197 #endif | |
| 198 Cyg_ASR *asr; // ASR function | |
| 199 #ifdef CYGSEM_KERNEL_SCHED_ASR_DATA_GLOBAL | |
| 200 static | |
| 201 #endif | |
| 202 CYG_ADDRWORD asr_data; // ASR data pointer | |
| 203 | |
| 204 // Default ASR function | |
| 205 static void asr_default(CYG_ADDRWORD data); | |
| 206 | |
| 207 public: | |
| 208 | |
| 209 // Public interface to ASR mechanism | |
| 210 | |
| 211 // Set, clear and get inhibit flag. | |
| 212 inline void set_asr_inhibit() { asr_inhibit = true; } | |
| 213 inline void clear_asr_inhibit() { asr_inhibit = false; } | |
| 214 inline cyg_bool get_asr_inhibit() { return asr_inhibit; } | |
| 215 | |
| 216 // Set and get pending flag. The flag is only cleared when the | |
| 217 // ASR is called. | |
| 218 inline void set_asr_pending() { asr_pending = true; } | |
| 219 inline cyg_bool get_asr_pending() { return asr_pending; } | |
| 220 | |
| 221 // Set a new ASR, returning the old one. | |
| 222 void set_asr( Cyg_ASR *new_asr, CYG_ADDRWORD new_data, | |
| 223 Cyg_ASR **old_asr, CYG_ADDRWORD *old_data); | |
| 224 | |
| 225 // Clear the ASR function back to the default. | |
| 226 void clear_asr(); | |
| 227 | |
| 228 #else | |
| 229 | |
| 230 public: | |
| 231 | |
| 232 // Even when we do not have ASRs enabled, we keep these functions | |
| 233 // available. This avoids excessive ifdefs in the rest of the | |
| 234 // kernel code. | |
| 235 inline void set_asr_inhibit() { } | |
| 236 inline void clear_asr_inhibit() { } | |
| 237 | |
| 238 #endif | |
| 239 | |
| 240 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL | |
| 241 | |
| 242 private: | |
| 243 | |
| 244 // For all priority inversion protocols we need to keep track of how | |
| 172 // many mutexes we have locked, including one which we are waiting to | 245 // many mutexes we have locked, including one which we are waiting to |
| 173 // lock, because we can inherit priority while sleeping just prior to | 246 // lock, because we can inherit priority while sleeping just prior to |
| 174 // wakeup. | 247 // wakeup. |
| 248 | |
| 175 cyg_count32 mutex_count; | 249 cyg_count32 mutex_count; |
| 176 | 250 |
| 251 protected: | |
| 252 // These are implementation functions that are common to all protocols. | |
| 253 | |
| 254 // Inherit the given priority. If thread is non-NULL the priority is | |
| 255 // being inherited from it, otherwise it has come from the mutex. | |
| 256 void set_inherited_priority( cyg_priority pri, Cyg_Thread *thread = 0 ); | |
| 257 | |
| 258 // Relay the priority of the ex-owner thread or from the queue if it | |
| 259 // has a higher priority than ours. | |
| 260 void relay_inherited_priority( Cyg_Thread *ex_owner, Cyg_ThreadQueue *pqueue); | |
| 261 | |
| 262 // Lose priority inheritance | |
| 263 void clear_inherited_priority(); | |
| 264 | |
| 177 public: | 265 public: |
| 178 // Count and uncount the number of mutexes held by | 266 // Count and uncount the number of mutexes held by |
| 179 // this thread. | 267 // this thread. |
| 180 void count_mutex() { mutex_count++; }; | 268 void count_mutex() { mutex_count++; }; |
| 181 void uncount_mutex() { mutex_count--; }; | 269 void uncount_mutex() { mutex_count--; }; |
| 270 | |
| 271 #if defined(CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_SIMPLE) | |
| 182 | 272 |
| 183 protected: | 273 protected: |
| 184 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INHERITANCE_SIMPLE | 274 |
| 185 | 275 // The simple priority inversion protocols simply needs |
| 186 // The simple priority inheritance mechanism simply needs | |
| 187 // somewhere to store the base priority of the current thread. | 276 // somewhere to store the base priority of the current thread. |
| 188 | 277 |
| 189 cyg_priority original_priority; // our original priority | 278 cyg_priority original_priority; // our original priority |
| 190 | 279 |
| 191 cyg_bool priority_inherited; // have we inherited? | 280 cyg_bool priority_inherited; // have we inherited? |
| 192 | 281 |
| 193 #endif | 282 #endif |
| 194 | 283 |
| 284 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_INHERIT | |
| 285 | |
| 195 public: | 286 public: |
| 196 | 287 |
| 197 // Inherit the priority of the provided thread if it | 288 // Inherit the priority of the provided thread if it |
| 198 // has higher priority than this. | 289 // has higher priority than this. |
| 199 void inherit_priority( Cyg_Thread *thread); | 290 void inherit_priority( Cyg_Thread *thread); |
| 204 | 295 |
| 205 // Lose priority inheritance | 296 // Lose priority inheritance |
| 206 void disinherit_priority(); | 297 void disinherit_priority(); |
| 207 | 298 |
| 208 #endif | 299 #endif |
| 300 | |
| 301 #ifdef CYGSEM_KERNEL_SYNCH_MUTEX_PRIORITY_INVERSION_PROTOCOL_CEILING | |
| 302 | |
| 303 public: | |
| 304 | |
| 305 // Set the priority of this thread to the given ceiling. | |
| 306 void set_priority_ceiling( cyg_priority pri ); | |
| 307 | |
| 308 // Clear the ceiling, if necessary. | |
| 309 void clear_priority_ceiling(); | |
| 310 | |
| 311 #endif | |
| 312 | |
| 313 #endif | |
| 209 | 314 |
| 210 }; | 315 }; |
| 211 | 316 |
| 212 // ------------------------------------------------------------------------- | 317 // ------------------------------------------------------------------------- |
| 213 // Simple inline accessor functions | 318 // Simple inline accessor functions |
