📄 mlqueue.cxx
字号:
CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("sched_info=%08x", sched_info); // Create all threads at maximum priority priority = (cyg_priority)sched_info; // point the next and prev field at this thread. next = prev = CYG_CLASSFROMBASE(Cyg_Thread, Cyg_SchedThread_Implementation, this); CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// Insert thread in front of thisvoidCyg_SchedThread_Implementation::insert( Cyg_Thread *thread){ CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("thread=%08x", thread); thread->next = CYG_CLASSFROMBASE(Cyg_Thread, Cyg_SchedThread_Implementation, this); thread->prev = prev; prev->next = thread; prev = thread; CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// remove this from queuevoidCyg_SchedThread_Implementation::remove(void){ CYG_REPORT_FUNCTION(); next->prev = prev; prev->next = next; next = prev = CYG_CLASSFROMBASE(Cyg_Thread, Cyg_SchedThread_Implementation, this); CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// Yield the processor to another threadvoidCyg_SchedThread_Implementation::yield(void){ CYG_REPORT_FUNCTION(); // Prevent preemption Cyg_Scheduler::lock(); Cyg_Thread *thread = CYG_CLASSFROMBASE(Cyg_Thread, Cyg_SchedThread_Implementation, this); // Only do this if this thread is running. If it is not, there // is no point. if( thread->get_state() == Cyg_Thread::RUNNING ) { // To yield we simply rotate the appropriate // run queue to the next thread and reschedule. CYG_ASSERTCLASS( thread, "Bad current thread"); Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler; CYG_ASSERTCLASS( sched, "Bad scheduler"); cyg_priority pri = thread->priority; Cyg_ThreadQueue_Implementation *queue = &sched->run_queue[pri]; queue->rotate(); if( queue->highpri() != thread ) sched->need_reschedule = true;#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 Cyg_Scheduler::unlock(); CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// Rotate the run queue at a specified priority.// (pri is the decider, no this, so the routine is static)voidCyg_SchedThread_Implementation::rotate_queue( cyg_priority pri ){ CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("priority=%d", pri); // Prevent preemption Cyg_Scheduler::lock(); Cyg_Scheduler *sched = &Cyg_Scheduler::scheduler; CYG_ASSERTCLASS( sched, "Bad scheduler"); Cyg_ThreadQueue_Implementation *queue = &sched->run_queue[pri]; if ( !queue->empty() ) { queue->rotate(); sched->need_reschedule = true; } // Unlock the scheduler and switch threads Cyg_Scheduler::unlock(); CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// Move this thread to the head of its queue// (not necessarily a scheduler queue)voidCyg_SchedThread_Implementation::to_queue_head( void ){ CYG_REPORT_FUNCTION(); // Prevent preemption Cyg_Scheduler::lock(); Cyg_Thread *thread = CYG_CLASSFROMBASE(Cyg_Thread, Cyg_SchedThread_Implementation, this); CYG_ASSERTCLASS( thread, "Bad current thread"); Cyg_ThreadQueue *q = thread->get_current_queue(); q->to_head( thread ); // Unlock the scheduler and switch threads Cyg_Scheduler::unlock(); CYG_REPORT_RETURN();}//==========================================================================// Cyg_ThreadQueue_Implementation class membersCyg_ThreadQueue_Implementation::Cyg_ThreadQueue_Implementation(){ CYG_REPORT_FUNCTION(); queue = NULL; // empty queue CYG_REPORT_RETURN();} voidCyg_ThreadQueue_Implementation::enqueue(Cyg_Thread *thread){ CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("thread=%08x", thread); if( queue == NULL ) queue = thread; else queue->insert(thread); thread->queue = CYG_CLASSFROMBASE(Cyg_ThreadQueue, Cyg_ThreadQueue_Implementation, this); CYG_REPORT_RETURN();}// -------------------------------------------------------------------------Cyg_Thread *Cyg_ThreadQueue_Implementation::dequeue(void){ CYG_REPORT_FUNCTYPE("returning thread %08x"); if( queue == NULL ) { CYG_REPORT_RETVAL(NULL); return NULL; } Cyg_Thread *thread = queue; if( thread->next == thread ) { // sole thread on list, NULL out ptr queue = NULL; } else { // advance to next and remove thread queue = thread->next; thread->remove(); } thread->queue = NULL; CYG_REPORT_RETVAL(thread); return thread;}// -------------------------------------------------------------------------Cyg_Thread *Cyg_ThreadQueue_Implementation::highpri(void){ CYG_REPORT_FUNCTYPE("returning thread %08x"); CYG_REPORT_RETVAL(queue); return queue;}// -------------------------------------------------------------------------voidCyg_ThreadQueue_Implementation::remove(Cyg_Thread *thread){ CYG_REPORT_FUNCTION(); CYG_REPORT_FUNCARG1("thread=%08x", thread); // If the thread we want it the at the head // of the list, and is on its own, clear the // list and return. Otherwise advance to the // next thread and remove ours. If the thread // is not at the head of the list, just dequeue // it. thread->queue = NULL; if( queue == thread ) { if( thread->next == thread ) { queue = NULL; return; } else queue = thread->next; } thread->Cyg_SchedThread_Implementation::remove(); CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// Rotate the front thread on the queue to the back.voidCyg_ThreadQueue_Implementation::rotate(void){ CYG_REPORT_FUNCTION(); queue = queue->next; CYG_REPORT_RETURN();}// -------------------------------------------------------------------------// Rotate or move the thread quoted to the front.voidCyg_ThreadQueue_Implementation::to_head(Cyg_Thread *thread){ CYG_REPORT_FUNCTION(); queue = thread; CYG_REPORT_RETURN();}// -------------------------------------------------------------------------#endif// -------------------------------------------------------------------------// EOF sched/mlqueue.cxx
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -