0flame0 发表于 2011-3-9 20:44:06

请问系统是怎样找到优先级最高的任务

假设有2个任务,优先级分别是4和5,先后调用rt_thread_startup进入对应优先级的就绪列表。请问以下程序是怎么找到优先级4的线程?程序怎么确定rt_thread_ready_priority_group的值为4?求解...
register rt_ubase_t number;
    /* find out the highest priority task */
    if (rt_thread_ready_priority_group & 0xff)
    {
      number = rt_lowest_bitmap;
    }
    else if (rt_thread_ready_priority_group & 0xff00)
    {
      number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 8) & 0xff] + 8;
    }
    else if (rt_thread_ready_priority_group & 0xff0000)
    {
      number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 16) & 0xff] + 16;
    }
    else
    {
      number = rt_lowest_bitmap[(rt_thread_ready_priority_group >> 24) & 0xff] + 24;
    }

#if RT_THREAD_PRIORITY_MAX > 32
    highest_ready_priority = (number << 3) + rt_lowest_bitmap];
#else
    highest_ready_priority = number;
#endif

0flame0 发表于 2011-3-10 15:31:02

理解了,昨天理解错了    rt_thread_ready_priority_group |= thread->number_mask; 这句话。
页: [1]
查看完整版本: 请问系统是怎样找到优先级最高的任务