diff packages/kernel/current/src/sched/mlqueue.cxx @ 2348:73a01c1a35ba

* src/sched/mlqueue.cxx (add_thread, yield): * src/sched/sched.cxx (unlock_inner, thread_entry): * include/mlqueue.hxx (class Cyg_SchedThread_Implementation): * include/kapidata.h (CYG_SCHEDTHREAD_TIMESLICE_MEMBER): * include/bitmap.hxx (class Cyg_SchedThread_Implementation): Reimplement timeslicing code. There is now a timeslice_count field in each thread which is moved to and from the per-CPU counter during thread dispatch. This approach has been taken to minimize the changes needed to SMP code. Scheduler specific thread functions handle counter save, restore and reset. These functions are defined (as empty inlines) even when timeslicing is disabled, or in non-timeslicing schedulers, to avoid adding ifdefs to the code (this change actually removes some). * tests/timeslice2.c: * cdl/kernel.cdl: Added timeslice2 test to test behaviour of timeslicing while being preempted.
author nickg
date Mon, 08 Jan 2007 16:20:13 +0000
parents a2c686b87032
children 74dbf4c3f2e1
line wrap: on
line diff
--- a/packages/kernel/current/src/sched/mlqueue.cxx
+++ b/packages/kernel/current/src/sched/mlqueue.cxx
@@ -236,6 +236,11 @@ Cyg_Scheduler_Implementation::add_thread
     // current thread, request a reschedule.
 
     set_need_reschedule(thread);
+
+    // Also reset the timeslice_count so that this thread gets a full
+    // timeslice once it begins to run.
+    
+    thread->timeslice_reset();
     
 #ifdef CYGPKG_KERNEL_SMP_SUPPORT
 
@@ -640,12 +645,14 @@ Cyg_SchedThread_Implementation::yield(vo
         
         if( queue->get_head() != thread )
             sched->set_need_reschedule();
+        else
+        {
+            // Reset the timeslice counter so that this thread gets a
+            // full quantum as a reward for yielding when it is
+            // eventually rescheduled.
+            thread->timeslice_reset();
+        }
 
-#ifdef CYGSEM_KERNEL_SCHED_TIMESLICE
-            // Reset the timeslice counter so that this thread gets a full
-            // quantum. 
-        else Cyg_Scheduler::reset_timeslice_count();
-#endif
     }
     
     // Unlock the scheduler and switch threads