#ifdef CYGFUN_KERNEL_THREADS_STACK_CHECKING
next->check_stack(); // before running it
#endif
-
+ current->timeslice_save();
+
// Switch contexts
HAL_THREAD_SWITCH_CONTEXT( ¤t->stack_ptr,
&next->stack_ptr );
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
}
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