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

Function _sched_insert_thread_locked

src/scheduler_mp.c:280–362  ·  view source on GitHub ↗

* @brief set READY and insert thread to ready queue * * @note caller must holding the `_mp_scheduler_lock` lock */

Source from the content-addressed store, hash-verified

278 * @note caller must holding the `_mp_scheduler_lock` lock
279 */
280static void _sched_insert_thread_locked(struct rt_thread *thread)
281{
282 int cpu_id;
283 int bind_cpu;
284 rt_uint32_t cpu_mask;
285
286 if ((RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_MASK) == RT_THREAD_READY)
287 {
288 /* already in ready queue */
289 return ;
290 }
291 else if (RT_SCHED_CTX(thread).oncpu != RT_CPU_DETACHED)
292 {
293 /**
294 * only YIELD -> READY, SUSPEND -> READY is allowed by this API. However,
295 * this is a RUNNING thread. So here we reset it's status and let it go.
296 */
297 RT_SCHED_CTX(thread).stat = RT_THREAD_RUNNING | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
298 return ;
299 }
300
301 /* READY thread, insert to ready queue */
302 RT_SCHED_CTX(thread).stat = RT_THREAD_READY | (RT_SCHED_CTX(thread).stat & ~RT_THREAD_STAT_MASK);
303
304 cpu_id = rt_hw_cpu_id();
305 bind_cpu = RT_SCHED_CTX(thread).bind_cpu;
306
307 /* insert thread to ready list */
308 if (bind_cpu == RT_CPUS_NR)
309 {
310#if RT_THREAD_PRIORITY_MAX > 32
311 rt_thread_ready_table[RT_SCHED_PRIV(thread).number] |= RT_SCHED_PRIV(thread).high_mask;
312#endif /* RT_THREAD_PRIORITY_MAX > 32 */
313 rt_thread_ready_priority_group |= RT_SCHED_PRIV(thread).number_mask;
314
315 /* there is no time slices left(YIELD), inserting thread before ready list*/
316 if((RT_SCHED_CTX(thread).stat & RT_THREAD_STAT_YIELD_MASK) != 0)
317 {
318 rt_list_insert_before(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
319 &RT_THREAD_LIST_NODE(thread));
320 }
321 /* there are some time slices left, inserting thread after ready list to schedule it firstly at next time*/
322 else
323 {
324 rt_list_insert_after(&(rt_thread_priority_table[RT_SCHED_PRIV(thread).current_priority]),
325 &RT_THREAD_LIST_NODE(thread));
326 }
327
328 cpu_mask = RT_CPU_MASK ^ (1 << cpu_id);
329 rt_hw_ipi_send(RT_SCHEDULE_IPI, cpu_mask);
330 }
331 else
332 {
333 struct rt_cpu *pcpu = rt_cpu_index(bind_cpu);
334
335#if RT_THREAD_PRIORITY_MAX > 32
336 pcpu->ready_table[RT_SCHED_PRIV(thread).number] |= RT_SCHED_PRIV(thread).high_mask;
337#endif /* RT_THREAD_PRIORITY_MAX > 32 */

Callers 2

rt_sched_insert_threadFunction · 0.85

Calls 5

rt_list_insert_beforeFunction · 0.85
rt_list_insert_afterFunction · 0.85
rt_cpu_indexFunction · 0.70
rt_hw_cpu_idFunction · 0.50
rt_hw_ipi_sendFunction · 0.50

Tested by

no test coverage detected