MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_sched_insert_thread

Function rt_sched_insert_thread

src/scheduler_up.c:490–533  ·  view source on GitHub ↗

* @brief This function will insert a thread to the system ready queue. The state of * thread will be set as READY and the thread will be removed from suspend queue. * * @param thread is the thread to be inserted. * * @note Please do not invoke this function in user application. */

Source from the content-addressed store, hash-verified

488 * @note Please do not invoke this function in user application.
489 */
490void rt_sched_insert_thread(struct rt_thread *thread)
491{
492 rt_base_t level;
493
494 RT_ASSERT(thread != RT_NULL);
495
496 /* disable interrupt */
497 level = rt_hw_interrupt_disable();
498
499 /* it's current thread, it should be RUNNING thread */
500 if (thread == rt_current_thread)
501 {
502 RT_SCHED_CTX(thread).stat = RT_THREAD_RUNNING | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
503 goto __exit;
504 }
505
506 /* READY thread, insert to ready queue */
507 RT_SCHED_CTX(thread).stat = RT_THREAD_READY | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
508 /* there is no time slices left(YIELD), inserting thread before ready list*/
509 if((RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_YIELD_MASK) != 0)
510 {
511 rt_list_insert_before(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
512 &RT_THREAD_LIST_NODE(thread));
513 }
514 /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
515 else
516 {
517 rt_list_insert_after(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
518 &RT_THREAD_LIST_NODE(thread));
519 }
520
521 LOG_D("insert thread[%.*s], the priority: %d",
522 RT_NAME_MAX, thread->parent.name, RT_SCHED_PRIV(rt_current_thread).current_priority);
523
524 /* set priority mask */
525#if RT_THREAD_PRIORITY_MAX > 32
526 rt_thread_ready_table[RT_SCHED_PRIV(thread).number] |= RT_SCHED_PRIV(thread).high_mask;
527#endif /* RT_THREAD_PRIORITY_MAX > 32 */
528 rt_thread_ready_priority_group |= RT_SCHED_PRIV(thread).number_mask;
529
530__exit:
531 /* enable interrupt */
532 rt_hw_interrupt_enable(level);
533}
534
535/**
536 * @brief This function will remove a thread from system ready queue.

Callers 6

rt_sched_thread_readyFunction · 0.70
rt_scheduleFunction · 0.70
_thread_timeoutFunction · 0.70
sender_timeoutFunction · 0.50
receiver_timeoutFunction · 0.50

Calls 4

rt_list_insert_beforeFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_hw_interrupt_disableFunction · 0.50
rt_hw_interrupt_enableFunction · 0.50

Tested by

no test coverage detected