This patch, just checked in, somewhat refactors the thread entry code
and fixes a bug noticed by Sergei Organov.


Index: kernel/current/ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/ChangeLog,v
retrieving revision 1.128
diff -u -5 -r1.128 ChangeLog
--- kernel/current/ChangeLog    23 Nov 2005 20:58:28 -0000      1.128
+++ kernel/current/ChangeLog    10 Jan 2006 15:50:30 -0000
@@ -1,5 +1,16 @@
+2006-01-10  Nick Garnett  <[EMAIL PROTECTED]>
+
+       * src/sched/sched.cxx: 
+       * include/sched.hxx (class Cyg_Scheduler): Added thread_entry()
+       member function. This handles thread startup housekeeping. Zeroing
+       the scheduler lock is handled by calling unlock() so that DSRs may
+       be run.
+
+       * src/common/thread.cxx (thread_entry): Refactored code to call
+       Cyg_Scheduler::thread_entry() instead of doing all the work here.       
+
 2005-11-23  Sergei Organov  <[EMAIL PROTECTED]>
 
        * doc/kernel.sgml: Fix description of CYG_ISR_CALL_DSR and
        CYG_ISR_HANDLED. Fix example isr_function() accordingly.
 
Index: kernel/current/include/sched.hxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/include/sched.hxx,v
retrieving revision 1.12
diff -u -5 -r1.12 sched.hxx
--- kernel/current/include/sched.hxx    23 May 2002 23:06:48 -0000      1.12
+++ kernel/current/include/sched.hxx    10 Jan 2006 15:50:31 -0000
@@ -174,10 +174,13 @@
     // decrement the lock but also look for a reschedule opportunity
     static void             unlock_reschedule();
 
     // release the preemption lock without rescheduling
     static void             unlock_simple();
+
+    // perform thread startup housekeeping
+    void Cyg_Scheduler::thread_entry( Cyg_Thread *thread );
     
     // Start execution of the scheduler
     static void start() CYGBLD_ATTRIB_NORET;
 
     // Start execution of the scheduler on the current CPU
Index: kernel/current/src/common/thread.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/common/thread.cxx,v
retrieving revision 1.20
diff -u -5 -r1.20 thread.cxx
--- kernel/current/src/common/thread.cxx        30 Jan 2003 07:02:53 -0000      
1.20
+++ kernel/current/src/common/thread.cxx        10 Jan 2006 15:50:32 -0000
@@ -84,28 +84,14 @@
 void
 Cyg_HardwareThread::thread_entry( Cyg_Thread *thread )
 {
     CYG_REPORT_FUNCTION();
 
-    Cyg_Scheduler::scheduler.clear_need_reschedule(); // finished rescheduling
-    Cyg_Scheduler::scheduler.set_current_thread(thread); // restore current 
thread pointer
-
-    CYG_INSTRUMENT_THREAD(ENTER,thread,0);
-    
-#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
-    // Reset the timeslice counter so that this thread gets a full
-    // quantum. 
-    Cyg_Scheduler::reset_timeslice_count();
-#endif
+    // Call the scheduler to do any housekeeping
+    Cyg_Scheduler::scheduler.thread_entry( thread );
     
-    // Zero the lock
-    HAL_REORDER_BARRIER ();            // Prevent the compiler from moving
-    Cyg_Scheduler::zero_sched_lock();     // the assignment into the code 
above.
-    HAL_REORDER_BARRIER();
-
     // Call entry point in a loop.
-
     for(;;)
     {
         thread->entry_point(thread->entry_data);
         thread->exit();
     }
@@ -1223,15 +1209,15 @@
 
 #  endif // CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE < 
CYGNUM_HAL_STACK_SIZE_MINIMUM
 # endif // CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE
 #endif // CYGNUM_HAL_STACK_SIZE_MINIMUM
 
-static char 
idle_thread_stack[CYGNUM_KERNEL_CPU_MAX][CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE];
-
 // Loop counter for debugging/housekeeping
 cyg_uint32 idle_thread_loops[CYGNUM_KERNEL_CPU_MAX];
 
+static char 
idle_thread_stack[CYGNUM_KERNEL_CPU_MAX][CYGNUM_KERNEL_THREADS_IDLE_STACK_SIZE];
+
 // -------------------------------------------------------------------------
 // Idle thread code.
 
 void
 idle_thread_main( CYG_ADDRESS data )
Index: kernel/current/src/sched/sched.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/sched/sched.cxx,v
retrieving revision 1.16
diff -u -5 -r1.16 sched.cxx
--- kernel/current/src/sched/sched.cxx  9 Aug 2002 17:13:28 -0000       1.16
+++ kernel/current/src/sched/sched.cxx  10 Jan 2006 15:50:33 -0000
@@ -307,10 +307,32 @@
 
     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);
+    
+#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
+    // Reset the timeslice counter so that this thread gets a full
+    // quantum. 
+    reset_timeslice_count();
+#endif
+    
+    // Finally unlock the scheduler. As well as clearing the scheduler
+    // lock this allows any pending DSRs to execute.
+    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
 // enters the scheduler.
 
 void Cyg_Scheduler::start()



-- 
Nick Garnett                                     eCos Kernel Architect
http://www.ecoscentric.com                The eCos and RedBoot experts


Reply via email to