Changeset b23c88e in mainline
- Timestamp:
- 2012-07-11T05:45:48Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b68ae24
- Parents:
- 9f8745c5
- Location:
- kernel/generic
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/arch.h
r9f8745c5 rb23c88e 53 53 #define TASK THE->task 54 54 #define AS THE->as 55 #define PREEMPTION_DISABLED THE->preemption_disabled 55 #define PREEMPTION_DISABLED (0 != THE->preemption_disabled) 56 #define PREEMPTION_ENABLED (0 == THE->preemption_disabled) 56 57 #define MAGIC UINT32_C(0xfacefeed) 57 58 -
kernel/generic/include/preemption.h
r9f8745c5 rb23c88e 38 38 extern void preemption_disable(void); 39 39 extern void preemption_enable(void); 40 extern void preemption_enable_noresched(void); 41 extern void preemption_enabled_scheduler(void); 42 43 40 44 41 45 #endif -
kernel/generic/include/proc/thread.h
r9f8745c5 rb23c88e 155 155 state_t state; 156 156 157 /** The thread would have been rescheduled had it not disabled preemption.*/ 158 bool need_resched; 159 157 160 /** Thread CPU. */ 158 161 cpu_t *cpu; -
kernel/generic/src/preempt/preemption.c
r9f8745c5 rb23c88e 38 38 #include <preemption.h> 39 39 #include <arch.h> 40 #include <arch/asm.h> 41 #include <arch/barrier.h> 40 #include <compiler/barrier.h> 42 41 #include <debug.h> 42 #include <proc/scheduler.h> 43 43 44 44 /** Increment preemption disabled counter. */ … … 46 46 { 47 47 THE->preemption_disabled++; 48 memory_barrier();48 compiler_barrier(); 49 49 } 50 50 … … 52 52 void preemption_enable(void) 53 53 { 54 preemption_enable_noresched(); 55 56 if (PREEMPTION_ENABLED && THREAD && THREAD->need_resched) { 57 preemption_enabled_scheduler(); 58 } 59 } 60 61 /** Decrement preemption disabled counter. */ 62 void preemption_enable_noresched(void) 63 { 54 64 ASSERT(PREEMPTION_DISABLED); 55 memory_barrier();65 compiler_barrier(); 56 66 THE->preemption_disabled--; 67 } 68 69 /** Preemption was enabled. Calls scheduler(). */ 70 void preemption_enabled_scheduler(void) 71 { 72 ASSERT(PREEMPTION_ENABLED); 73 74 /* 75 * Avoid a race between a thread about to invoke the scheduler() 76 * after checking THREAD->need_resched and an interrupt that 77 * occurs right after the check. 78 * 79 * Also ensures that code that relies on disabled interrupts 80 * to suppress preemption continues to work. 81 */ 82 if (!interrupts_disabled()) { 83 scheduler(); 84 } 57 85 } 58 86 -
kernel/generic/src/proc/scheduler.c
r9f8745c5 rb23c88e 404 404 ASSERT((!THREAD) || (irq_spinlock_locked(&THREAD->lock))); 405 405 ASSERT(CPU != NULL); 406 ASSERT(interrupts_disabled()); 406 407 407 408 /* … … 419 420 /* Must be run after the switch to scheduler stack */ 420 421 after_thread_ran(); 422 423 THREAD->need_resched = false; 421 424 422 425 switch (THREAD->state) { -
kernel/generic/src/proc/thread.c
r9f8745c5 rb23c88e 375 375 thread->nomigrate = 0; 376 376 thread->state = Entering; 377 thread->need_resched = false; 377 378 378 379 timeout_initialize(&thread->sleep_timeout); -
kernel/generic/src/time/clock.c
r9f8745c5 rb23c88e 212 212 irq_spinlock_unlock(&THREAD->lock, false); 213 213 214 if ((!ticks) && (!PREEMPTION_DISABLED)) { 215 scheduler(); 214 if (ticks == 0) { 215 if (PREEMPTION_ENABLED) { 216 scheduler(); 216 217 #ifdef CONFIG_UDEBUG 217 /*218 219 220 221 istate_t *istate = THREAD->udebug.uspace_state;222 if ((istate) && (istate_from_uspace(istate)))223 udebug_before_thread_runs();218 /* 219 * Give udebug chance to stop the thread 220 * before it begins executing userspace code. 221 */ 222 istate_t *istate = THREAD->udebug.uspace_state; 223 if ((istate) && (istate_from_uspace(istate))) 224 udebug_before_thread_runs(); 224 225 #endif 226 } else { 227 THREAD->need_resched = true; 228 } 225 229 } 226 230 }
Note:
See TracChangeset
for help on using the changeset viewer.