This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: Thread entry code refactored
- From: Nick Garnett <nickg at ecoscentric dot com>
- To: ecos-patches at ecos dot sourceware dot org
- Date: 19 Jan 2006 17:57:17 +0000
- Subject: Re: Thread entry code refactored
- References: <m3k6d89itw.fsf@xl5.calivar.com>
Nick Garnett <nickg@ecoscentric.com> writes:
> This patch, just checked in, somewhat refactors the thread entry code
> and fixes a bug noticed by Sergei Organov.
I recently found a bug in this, patch attached and applied:
Index: ChangeLog
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/ChangeLog,v
retrieving revision 1.129
diff -u -5 -r1.129 ChangeLog
--- ChangeLog 10 Jan 2006 15:52:54 -0000 1.129
+++ ChangeLog 19 Jan 2006 17:52:40 -0000
@@ -1,5 +1,17 @@
+2006-01-19 Nick Garnett <nickg@ecoscentric.com>
+
+ * src/sched/sched.cxx (thread_entry): Fixed a bug which could
+ cause a thread to be started with a non-zero scheduler lock. The
+ previous code only decremented it by 1 so if the previous thread
+ was executing with the lock > 1 the thread ended up with a
+ non-zero lock. This is fixed by decrementing the lock in a loop
+ until it reaches zero.
+
+ * src/common/thread.cxx (idle_thread_main): Added an assert for a
+ non-zero scheduler lock.
+
2006-01-10 Nick Garnett <nickg@ecoscentric.com>
* src/sched/sched.cxx:
* include/sched.hxx (class Cyg_Scheduler): Added thread_entry()
member function. This handles thread startup housekeeping. Zeroing
Index: src/common/thread.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/common/thread.cxx,v
retrieving revision 1.21
diff -u -5 -r1.21 thread.cxx
--- src/common/thread.cxx 10 Jan 2006 15:52:54 -0000 1.21
+++ src/common/thread.cxx 19 Jan 2006 17:52:41 -0000
@@ -1228,10 +1228,11 @@
{
idle_thread_loops[CYG_KERNEL_CPU_THIS()]++;
HAL_IDLE_THREAD_ACTION(idle_thread_loops[CYG_KERNEL_CPU_THIS()]);
+ CYG_ASSERT( Cyg_Scheduler::get_sched_lock() == 0, "Scheduler lock not zero" );
#if 0
// For testing, it is useful to be able to fake
// clock interrupts in the idle thread.
Cyg_Clock::real_time_clock->tick();
Index: src/sched/sched.cxx
===================================================================
RCS file: /cvs/ecos/ecos/packages/kernel/current/src/sched/sched.cxx,v
retrieving revision 1.17
diff -u -5 -r1.17 sched.cxx
--- src/sched/sched.cxx 10 Jan 2006 15:52:54 -0000 1.17
+++ src/sched/sched.cxx 19 Jan 2006 17:52:42 -0000
@@ -324,12 +324,15 @@
// quantum.
reset_timeslice_count();
#endif
// Finally unlock the scheduler. As well as clearing the scheduler
- // lock this allows any pending DSRs to execute.
- unlock();
+ // 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
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com The eCos and RedBoot experts
Besuchen Sie uns vom 14.-16.02.06 auf der Embedded World 2006, Stand 11-222
Visit us at Embedded World 2006, NÃrnberg, Germany, 14-16 Feb, Stand 11-222