]> git.kernelconcepts.de Git - karo-tx-redboot.git/blobdiff - packages/kernel/v2_0/src/sched/sched.cxx
unified MX27, MX25, MX37 trees
[karo-tx-redboot.git] / packages / kernel / v2_0 / src / sched / sched.cxx
index c302d78ceaca4d31122076f186417fbf30d1c58e..978d14f27349a181dee4122b32fa47307902bfef 100644 (file)
@@ -198,7 +198,8 @@ void Cyg_Scheduler::unlock_inner( cyg_ucount32 new_lock )
 #ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
                 next->check_stack(); // before running it
 #endif
-
+                current->timeslice_save();
+                
                 // Switch contexts
                 HAL_THREAD_SWITCH_CONTEXT( &current->stack_ptr,
                                            &next->stack_ptr );
@@ -221,13 +222,9 @@ void Cyg_Scheduler::unlock_inner( cyg_ucount32 new_lock )
                 CYG_ASSERTCLASS( current, "Bad current thread" );
 
                 current_thread[CYG_KERNEL_CPU_THIS()] = current;   // restore current thread pointer
-            }
 
-#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
-            // Reset the timeslice counter so that this thread gets a full
-            // quantum. 
-            reset_timeslice_count();
-#endif
+                current->timeslice_restore();
+            }
 
             clear_need_reschedule();    // finished rescheduling
         }
@@ -308,6 +305,28 @@ void Cyg_Scheduler::unlock_inner( cyg_ucount32 new_lock )
     CYG_FAIL( "Should not be executed" );
 }
 
+// -------------------------------------------------------------------------
+// Thread startup. This is called from Cyg_Thread::thread_entry() and
+// performs some housekeeping for a newly started thread.
+
+void Cyg_Scheduler::thread_entry( Cyg_Thread *thread )
+{
+    clear_need_reschedule();            // finished rescheduling
+    set_current_thread(thread);         // restore current thread pointer
+
+    CYG_INSTRUMENT_THREAD(ENTER,thread,0);
+
+    thread->timeslice_reset();
+    thread->timeslice_restore();
+    
+    // Finally unlock the scheduler. As well as clearing the scheduler
+    // lock this allows any pending DSRs to execute. The new thread
+    // must start with a lock of zero, so we keep unlocking until the
+    // lock reaches zero.
+    while( get_sched_lock() != 0 )
+        unlock();    
+}
+
 // -------------------------------------------------------------------------
 // Start the scheduler. This is called after the initial threads have been
 // created to start scheduling. It gets any other CPUs running, and then