RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
载入中...
搜索中...
未找到
Thread Management
+ Thread Management 的协作图:

结构体

struct  rt_cpu_usage_stats
 
struct  rt_cpu
 
struct  rt_interrupt_context
 
struct  rt_thread
 

宏定义

#define RT_THREAD_INIT   0x00
 
#define RT_THREAD_CLOSE   0x01
 
#define RT_THREAD_READY   0x02
 
#define RT_THREAD_RUNNING   0x03
 
#define RT_THREAD_SUSPEND_MASK   0x04
 
#define RT_SIGNAL_COMMON_WAKEUP_MASK   0x02
 
#define RT_SIGNAL_KILL_WAKEUP_MASK   0x01
 
#define RT_THREAD_SUSPEND_INTERRUPTIBLE   (RT_THREAD_SUSPEND_MASK)
 
#define RT_THREAD_SUSPEND   RT_THREAD_SUSPEND_INTERRUPTIBLE
 
#define RT_THREAD_SUSPEND_KILLABLE   (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK)
 
#define RT_THREAD_SUSPEND_UNINTERRUPTIBLE   (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK)
 
#define RT_THREAD_STAT_MASK   0x07
 
#define RT_THREAD_STAT_YIELD   0x08
 
#define RT_THREAD_STAT_YIELD_MASK   RT_THREAD_STAT_YIELD
 
#define RT_THREAD_STAT_SIGNAL   0x10
 
#define RT_THREAD_STAT_SIGNAL_READY   (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)
 
#define RT_THREAD_STAT_SIGNAL_WAIT   0x20
 
#define RT_THREAD_STAT_SIGNAL_PENDING   0x40
 
#define RT_THREAD_STAT_SIGNAL_MASK   0xf0
 
#define RT_THREAD_CTRL_STARTUP   0x00
 
#define RT_THREAD_CTRL_CLOSE   0x01
 
#define RT_THREAD_CTRL_CHANGE_PRIORITY   0x02
 
#define RT_THREAD_CTRL_INFO   0x03
 
#define RT_THREAD_CTRL_BIND_CPU   0x04
 
#define rt_current_thread   rt_thread_self()
 
#define LWP_IS_USER_MODE(t)
 
#define RT_SCHEDULER_STACK_CHECK(thr)
 

类型定义

typedef struct rt_cpu_usage_statsrt_cpu_usage_stats_t
 
typedef struct rt_cpurt_cpu_t
 
typedef struct rt_interrupt_contextrt_interrupt_context_t
 
typedef void(* rt_thread_cleanup_t) (struct rt_thread *tid)
 
typedef struct rt_threadrt_thread_t
 
typedef void(* rt_thread_inited_hookproto_t) (rt_thread_t thread)
 

枚举

enum  { RT_INTERRUPTIBLE = 0 , RT_KILLABLE , RT_UNINTERRUPTIBLE }
 

函数

rt_err_t rt_thread_init (struct rt_thread *thread, const char *name, void(*entry)(void *parameter), void *parameter, void *stack_start, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
 
 RTM_EXPORT (rt_thread_init)
 
rt_thread_t rt_thread_self (void)
 
 RTM_EXPORT (rt_thread_self)
 
rt_err_t rt_thread_startup (rt_thread_t thread)
 
 RTM_EXPORT (rt_thread_startup)
 
rt_err_t rt_thread_close (rt_thread_t thread)
 
 RTM_EXPORT (rt_thread_close)
 
rt_err_t rt_thread_detach (rt_thread_t thread)
 
 RTM_EXPORT (rt_thread_detach)
 
rt_thread_t rt_thread_create (const char *name, void(*entry)(void *parameter), void *parameter, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
 
 RTM_EXPORT (rt_thread_create)
 
rt_err_t rt_thread_delete (rt_thread_t thread)
 
 RTM_EXPORT (rt_thread_delete)
 
rt_err_t rt_thread_yield (void)
 
 RTM_EXPORT (rt_thread_yield)
 
rt_err_t rt_thread_delay (rt_tick_t tick)
 
 RTM_EXPORT (rt_thread_delay)
 
rt_err_t rt_thread_delay_until (rt_tick_t *tick, rt_tick_t inc_tick)
 
 RTM_EXPORT (rt_thread_delay_until)
 
rt_err_t rt_thread_mdelay (rt_int32_t ms)
 
 RTM_EXPORT (rt_thread_mdelay)
 
rt_err_t rt_thread_control (rt_thread_t thread, int cmd, void *arg)
 
 RTM_EXPORT (rt_thread_control)
 
rt_err_t rt_thread_suspend_to_list (rt_thread_t thread, rt_list_t *susp_list, int ipc_flags, int suspend_flag)
 
 RTM_EXPORT (rt_thread_suspend_to_list)
 
rt_err_t rt_thread_suspend_with_flag (rt_thread_t thread, int suspend_flag)
 
 RTM_EXPORT (rt_thread_suspend_with_flag)
 
rt_err_t rt_thread_suspend (rt_thread_t thread)
 
 RTM_EXPORT (rt_thread_suspend)
 
rt_err_t rt_thread_resume (rt_thread_t thread)
 
 RTM_EXPORT (rt_thread_resume)
 
rt_thread_t rt_thread_find (char *name)
 
 RTM_EXPORT (rt_thread_find)
 
rt_err_t rt_thread_get_name (rt_thread_t thread, char *name, rt_uint8_t name_size)
 
 RTM_EXPORT (rt_thread_get_name)
 
void rt_thread_suspend_sethook (void(*hook)(rt_thread_t thread))
 
void rt_thread_resume_sethook (void(*hook)(rt_thread_t thread))
 
 RT_OBJECT_HOOKLIST_DECLARE (rt_thread_inited_hookproto_t, rt_thread_inited)
 
void rt_thread_idle_init (void)
 
rt_err_t rt_thread_idle_sethook (void(*hook)(void))
 
rt_err_t rt_thread_idle_delhook (void(*hook)(void))
 
rt_thread_t rt_thread_idle_gethandler (void)
 
void rt_system_scheduler_init (void)
 
void rt_system_scheduler_start (void)
 
void rt_schedule (void)
 
void rt_scheduler_do_irq_switch (void *context)
 
rt_base_t rt_enter_critical (void)
 
void rt_exit_critical (void)
 
void rt_exit_critical_safe (rt_base_t critical_level)
 
rt_uint16_t rt_critical_level (void)
 
void rt_scheduler_sethook (void(*hook)(rt_thread_t from, rt_thread_t to))
 
void rt_scheduler_switch_sethook (void(*hook)(struct rt_thread *tid))
 
void rt_scheduler_ipi_handler (int vector, void *param)
 
void rt_schedule_insert_thread (struct rt_thread *thread)
 
void rt_schedule_remove_thread (struct rt_thread *thread)
 

详细描述

the thread management

RT-Thread operating system supports multitask systems, which are based on thread scheduling.

宏定义说明

◆ RT_THREAD_INIT

#define RT_THREAD_INIT   0x00

Initialized status

在文件 rtdef.h604 行定义.

◆ RT_THREAD_CLOSE

#define RT_THREAD_CLOSE   0x01

Closed status

在文件 rtdef.h605 行定义.

◆ RT_THREAD_READY

#define RT_THREAD_READY   0x02

Ready status

在文件 rtdef.h606 行定义.

◆ RT_THREAD_RUNNING

#define RT_THREAD_RUNNING   0x03

Running status

在文件 rtdef.h607 行定义.

◆ RT_THREAD_SUSPEND_MASK

#define RT_THREAD_SUSPEND_MASK   0x04

在文件 rtdef.h619 行定义.

◆ RT_SIGNAL_COMMON_WAKEUP_MASK

#define RT_SIGNAL_COMMON_WAKEUP_MASK   0x02

在文件 rtdef.h620 行定义.

◆ RT_SIGNAL_KILL_WAKEUP_MASK

#define RT_SIGNAL_KILL_WAKEUP_MASK   0x01

在文件 rtdef.h621 行定义.

◆ RT_THREAD_SUSPEND_INTERRUPTIBLE

#define RT_THREAD_SUSPEND_INTERRUPTIBLE   (RT_THREAD_SUSPEND_MASK)

Suspend interruptable 0x4

在文件 rtdef.h623 行定义.

◆ RT_THREAD_SUSPEND

#define RT_THREAD_SUSPEND   RT_THREAD_SUSPEND_INTERRUPTIBLE

在文件 rtdef.h624 行定义.

◆ RT_THREAD_SUSPEND_KILLABLE

#define RT_THREAD_SUSPEND_KILLABLE   (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK)

Suspend with killable 0x6

在文件 rtdef.h625 行定义.

◆ RT_THREAD_SUSPEND_UNINTERRUPTIBLE

#define RT_THREAD_SUSPEND_UNINTERRUPTIBLE   (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK)

Suspend with uninterruptable 0x7

在文件 rtdef.h626 行定义.

◆ RT_THREAD_STAT_MASK

#define RT_THREAD_STAT_MASK   0x07

在文件 rtdef.h627 行定义.

◆ RT_THREAD_STAT_YIELD

#define RT_THREAD_STAT_YIELD   0x08

indicate whether remaining_tick has been reloaded since last schedule

在文件 rtdef.h629 行定义.

◆ RT_THREAD_STAT_YIELD_MASK

#define RT_THREAD_STAT_YIELD_MASK   RT_THREAD_STAT_YIELD

在文件 rtdef.h630 行定义.

◆ RT_THREAD_STAT_SIGNAL

#define RT_THREAD_STAT_SIGNAL   0x10

task hold signals

在文件 rtdef.h632 行定义.

◆ RT_THREAD_STAT_SIGNAL_READY

#define RT_THREAD_STAT_SIGNAL_READY   (RT_THREAD_STAT_SIGNAL | RT_THREAD_READY)

在文件 rtdef.h633 行定义.

◆ RT_THREAD_STAT_SIGNAL_WAIT

#define RT_THREAD_STAT_SIGNAL_WAIT   0x20

task is waiting for signals

在文件 rtdef.h634 行定义.

◆ RT_THREAD_STAT_SIGNAL_PENDING

#define RT_THREAD_STAT_SIGNAL_PENDING   0x40

signals is held and it has not been procressed

在文件 rtdef.h635 行定义.

◆ RT_THREAD_STAT_SIGNAL_MASK

#define RT_THREAD_STAT_SIGNAL_MASK   0xf0

在文件 rtdef.h636 行定义.

◆ RT_THREAD_CTRL_STARTUP

#define RT_THREAD_CTRL_STARTUP   0x00

thread control command definitions Startup thread.

在文件 rtdef.h641 行定义.

◆ RT_THREAD_CTRL_CLOSE

#define RT_THREAD_CTRL_CLOSE   0x01

Close thread.

在文件 rtdef.h642 行定义.

◆ RT_THREAD_CTRL_CHANGE_PRIORITY

#define RT_THREAD_CTRL_CHANGE_PRIORITY   0x02

Change thread priority.

在文件 rtdef.h643 行定义.

◆ RT_THREAD_CTRL_INFO

#define RT_THREAD_CTRL_INFO   0x03

Get thread information.

在文件 rtdef.h644 行定义.

◆ RT_THREAD_CTRL_BIND_CPU

#define RT_THREAD_CTRL_BIND_CPU   0x04

Set thread bind cpu.

在文件 rtdef.h645 行定义.

◆ rt_current_thread

#define rt_current_thread   rt_thread_self()

在文件 rtdef.h744 行定义.

◆ LWP_IS_USER_MODE

#define LWP_IS_USER_MODE ( t)
值:
(0)

在文件 rtdef.h958 行定义.

◆ RT_SCHEDULER_STACK_CHECK

#define RT_SCHEDULER_STACK_CHECK ( thr)

在文件 rtthread.h228 行定义.

类型定义说明

◆ rt_cpu_usage_stats_t

在文件 rtdef.h657 行定义.

◆ rt_cpu_t

typedef struct rt_cpu* rt_cpu_t

在文件 rtdef.h742 行定义.

◆ rt_interrupt_context_t

interrupt/exception frame handling

◆ rt_thread_cleanup_t

typedef void(* rt_thread_cleanup_t) (struct rt_thread *tid)

在文件 rtdef.h845 行定义.

◆ rt_thread_t

typedef struct rt_thread* rt_thread_t

在文件 rtdef.h953 行定义.

◆ rt_thread_inited_hookproto_t

typedef void(* rt_thread_inited_hookproto_t) (rt_thread_t thread)

Sets a hook function when a thread is initialized.

参数
threadis the target thread that initializing

在文件 rtthread.h197 行定义.

枚举类型说明

◆ anonymous enum

anonymous enum
枚举值
RT_INTERRUPTIBLE 
RT_KILLABLE  
RT_UNINTERRUPTIBLE  

在文件 rtdef.h612 行定义.

613{
617};
@ RT_KILLABLE
@ RT_INTERRUPTIBLE
@ RT_UNINTERRUPTIBLE

函数说明

◆ rt_thread_init()

rt_err_t rt_thread_init ( struct rt_thread * thread,
const char * name,
void(* entry )(void *parameter),
void * parameter,
void * stack_start,
rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick )

This function will initialize a thread. It's used to initialize a static thread object.

参数
threadis the static thread object.
nameis the name of thread, which shall be unique.
entryis the entry function of thread.
parameteris the parameter of thread enter function.
stack_startis the start address of thread stack.
stack_sizeis the size of thread stack.
priorityis the priority of thread.
tickis the time slice if there are same priority thread.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c328 行定义.

336{
337 /* parameter check */
338 RT_ASSERT(thread != RT_NULL);
339 RT_ASSERT(stack_start != RT_NULL);
340 RT_ASSERT(tick != 0);
341
342 /* clean memory data of thread */
343 rt_memset(thread, 0x0, sizeof(struct rt_thread));
344
345 /* initialize thread object */
347
348 return _thread_init(thread,
349 name,
350 entry,
351 parameter,
352 stack_start,
353 stack_size,
354 priority,
355 tick);
356}
void rt_object_init(struct rt_object *object, enum rt_object_class_type type, const char *name)
This function will initialize an object and add it to object system management.
struct rt_object * rt_object_t
@ RT_Object_Class_Thread
#define RT_ASSERT(EX)
#define RT_NULL

引用了 rt_thread::entry, rt_thread::parameter, RT_ASSERT, RT_NULL, RT_Object_Class_Thread, rt_object_init() , 以及 rt_thread::stack_size.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [1/18]

RTM_EXPORT ( rt_thread_init )

引用了 rt_thread_init().

+ 函数调用图:

◆ rt_thread_self()

rt_thread_t rt_thread_self ( void )

This function will return self thread object.

返回
The self thread object.

在文件 thread.c364 行定义.

365{
366#ifndef RT_USING_SMP
367 return rt_cpu_self()->current_thread;
368
369#elif defined (ARCH_USING_HW_THREAD_SELF)
370 return rt_hw_thread_self();
371
372#else /* !ARCH_USING_HW_THREAD_SELF */
373 rt_thread_t self;
374 rt_base_t lock;
375
377 self = rt_cpu_self()->current_thread;
379
380 return self;
381#endif /* ARCH_USING_HW_THREAD_SELF */
382}
struct rt_cpu * rt_cpu_self(void)
This fucntion will return current cpu object.
struct rt_thread * rt_thread_t
#define rt_hw_local_irq_disable
定义 rthw.h:152
#define rt_hw_local_irq_enable
定义 rthw.h:153
rt_int32_t rt_base_t
struct rt_thread * current_thread

引用了 rt_cpu::current_thread, rt_cpu_self(), rt_hw_local_irq_disable , 以及 rt_hw_local_irq_enable.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [2/18]

RTM_EXPORT ( rt_thread_self )

引用了 rt_thread_self().

+ 函数调用图:

◆ rt_thread_startup()

rt_err_t rt_thread_startup ( rt_thread_t thread)

This function will start a thread and put it to system ready queue.

参数
threadis the thread to be started.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c393 行定义.

394{
395 /* parameter check */
396 RT_ASSERT(thread != RT_NULL);
399
400 LOG_D("startup a thread:%s with priority:%d",
401 thread->parent.name, thread->current_priority);
402
403 /* calculate priority attribute and reset thread stat to suspend */
404 rt_sched_thread_startup(thread);
405
406 /* resume and do a schedule if scheduler is available */
407 rt_thread_resume(thread);
408
409 return RT_EOK;
410}
int stat(const char *file, struct stat *buf)
rt_uint8_t rt_object_get_type(rt_object_t object)
This function will return the type of object without RT_Object_Class_Static flag.
#define RT_THREAD_STAT_MASK
rt_err_t rt_thread_resume(rt_thread_t thread)
This function will resume a thread and put it to system ready queue.
#define RT_THREAD_INIT
#define LOG_D(...)
#define RT_SCHED_CTX(thread)
const char * name
struct rt_object parent

引用了 LOG_D, rt_object::name, rt_thread::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Thread, rt_object_get_type(), RT_SCHED_CTX, RT_THREAD_INIT, rt_thread_resume(), RT_THREAD_STAT_MASK , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [3/18]

RTM_EXPORT ( rt_thread_startup )

引用了 rt_thread_startup().

+ 函数调用图:

◆ rt_thread_close()

rt_err_t rt_thread_close ( rt_thread_t thread)

This function will close a thread. The thread object will be removed from thread queue and detached/deleted from the system object management. It's different from rt_thread_delete or rt_thread_detach that this will not enqueue the closing thread to cleanup queue.

参数
threadis the thread to be closed.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c424 行定义.

425{
427 rt_uint8_t thread_status;
428
429 /* forbid scheduling on current core if closing current thread */
431
432 /* before checking status of scheduler */
433 rt_sched_lock(&slvl);
434
435 /* check if thread is already closed */
436 thread_status = rt_sched_thread_get_stat(thread);
437 if (thread_status != RT_THREAD_CLOSE)
438 {
439 if (thread_status != RT_THREAD_INIT)
440 {
441 /* remove from schedule */
442 rt_sched_remove_thread(thread);
443 }
444
445 /* release thread timer */
446 rt_timer_detach(&(thread->thread_timer));
447
448 /* change stat */
449 rt_sched_thread_close(thread);
450 }
451
452 /* scheduler works are done */
453 rt_sched_unlock(slvl);
454
455 return RT_EOK;
456}
rt_err_t rt_timer_detach(rt_timer_t timer)
This function will detach a timer from timer management.
#define RT_THREAD_CLOSE
rt_thread_t rt_thread_self(void)
This function will return self thread object.
rt_uint16_t rt_critical_level(void)
Get the scheduler lock level.
rt_ubase_t rt_sched_lock_level_t
unsigned char rt_uint8_t
rt_uint8_t rt_sched_thread_get_stat(struct rt_thread *thread)
rt_err_t rt_sched_thread_close(struct rt_thread *thread)
rt_err_t rt_sched_lock(rt_sched_lock_level_t *plvl)
rt_err_t rt_sched_unlock(rt_sched_lock_level_t level)
RT_SCHED_THREAD_CTX struct rt_timer thread_timer

引用了 RT_ASSERT, rt_critical_level(), rt_sched_lock(), rt_sched_thread_close(), rt_sched_thread_get_stat(), rt_sched_unlock(), RT_THREAD_CLOSE, RT_THREAD_INIT, rt_thread_self(), rt_timer_detach() , 以及 rt_thread::thread_timer.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [4/18]

RTM_EXPORT ( rt_thread_close )

引用了 rt_thread_close().

+ 函数调用图:

◆ rt_thread_detach()

rt_err_t rt_thread_detach ( rt_thread_t thread)

This function will detach a thread. The thread object will be removed from thread queue and detached/deleted from the system object management.

参数
threadis the thread to be deleted.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c470 行定义.

471{
472 /* parameter check */
473 RT_ASSERT(thread != RT_NULL);
476
477 return _thread_detach(thread);
478}
rt_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.

引用了 RT_ASSERT, RT_NULL, RT_Object_Class_Thread, rt_object_get_type() , 以及 rt_object_is_systemobject().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [5/18]

RTM_EXPORT ( rt_thread_detach )

引用了 rt_thread_detach().

+ 函数调用图:

◆ rt_thread_create()

rt_thread_t rt_thread_create ( const char * name,
void(* entry )(void *parameter),
void * parameter,
rt_uint32_t stack_size,
rt_uint8_t priority,
rt_uint32_t tick )

This function will create a thread object and allocate thread object memory. and stack.

参数
nameis the name of thread, which shall be unique.
entryis the entry function of thread.
parameteris the parameter of thread enter function.
stack_sizeis the size of thread stack.
priorityis the priority of thread.
tickis the time slice if there are same priority thread.
返回
If the return value is a rt_thread structure pointer, the function is successfully executed. If the return value is RT_NULL, it means this operation failed.

在文件 thread.c523 行定义.

529{
530 /* parameter check */
531 RT_ASSERT(tick != 0);
532
533 struct rt_thread *thread;
534 void *stack_start;
535
537 name);
538 if (thread == RT_NULL)
539 return RT_NULL;
540
541 stack_start = (void *)RT_KERNEL_MALLOC(stack_size);
542 if (stack_start == RT_NULL)
543 {
544 /* allocate stack failure */
546
547 return RT_NULL;
548 }
549
550 _thread_init(thread,
551 name,
552 entry,
553 parameter,
554 stack_start,
556 priority,
557 tick);
558
559 return thread;
560}
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
rt_object_t rt_object_allocate(enum rt_object_class_type type, const char *name)
This function will allocate an object from object system.
#define RT_KERNEL_MALLOC(sz)
void * parameter
void * entry
rt_uint32_t stack_size

引用了 rt_thread::entry, rt_thread::parameter, RT_ASSERT, RT_KERNEL_MALLOC, RT_NULL, rt_object_allocate(), RT_Object_Class_Thread, rt_object_delete() , 以及 rt_thread::stack_size.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [6/18]

RTM_EXPORT ( rt_thread_create )

引用了 rt_thread_create().

+ 函数调用图:

◆ rt_thread_delete()

rt_err_t rt_thread_delete ( rt_thread_t thread)

This function will delete a thread. The thread object will be removed from thread queue and deleted from system object management in the idle thread.

参数
threadis the thread to be deleted.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c572 行定义.

573{
574 /* parameter check */
575 RT_ASSERT(thread != RT_NULL);
578
579 return _thread_detach(thread);
580}
#define RT_FALSE

引用了 RT_ASSERT, RT_FALSE, RT_NULL, RT_Object_Class_Thread, rt_object_get_type() , 以及 rt_object_is_systemobject().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [7/18]

RTM_EXPORT ( rt_thread_delete )

引用了 rt_thread_delete().

+ 函数调用图:

◆ rt_thread_yield()

rt_err_t rt_thread_yield ( void )

This function will let current thread yield processor, and scheduler will choose the highest thread to run. After yield processor, the current thread is still in READY state.

返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c592 行定义.

593{
595 rt_sched_lock(&slvl);
596
598
600
601 return RT_EOK;
602}
rt_err_t rt_sched_thread_yield(struct rt_thread *thread)
rt_err_t rt_sched_unlock_n_resched(rt_sched_lock_level_t level)

引用了 rt_sched_lock(), rt_sched_thread_yield(), rt_sched_unlock_n_resched() , 以及 rt_thread_self().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [8/18]

RTM_EXPORT ( rt_thread_yield )

引用了 rt_thread_yield().

+ 函数调用图:

◆ rt_thread_delay()

rt_err_t rt_thread_delay ( rt_tick_t tick)

This function will let current thread delay for some ticks.

参数
tickis the delay ticks.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c676 行定义.

677{
678 return _thread_sleep(tick);
679}
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [9/18]

RTM_EXPORT ( rt_thread_delay )

引用了 rt_thread_delay().

+ 函数调用图:

◆ rt_thread_delay_until()

rt_err_t rt_thread_delay_until ( rt_tick_t * tick,
rt_tick_t inc_tick )

This function will let current thread delay until (*tick + inc_tick).

参数
tickis the tick of last wakeup.
inc_tickis the increment tick.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c692 行定义.

693{
694 struct rt_thread *thread;
695 rt_tick_t cur_tick;
696 rt_base_t critical_level;
697
698 RT_ASSERT(tick != RT_NULL);
699
700 /* set to current thread */
701 thread = rt_thread_self();
702 RT_ASSERT(thread != RT_NULL);
704
705 /* reset thread error */
706 thread->error = RT_EOK;
707
708 /* disable interrupt */
709 critical_level = rt_enter_critical();
710
711 cur_tick = rt_tick_get();
712 if (cur_tick - *tick < inc_tick)
713 {
714 rt_tick_t left_tick;
715
716 *tick += inc_tick;
717 left_tick = *tick - cur_tick;
718
719 /* suspend thread */
721
722 /* reset the timeout of thread timer and start it */
724 rt_timer_start(&(thread->thread_timer));
725
726 rt_exit_critical_safe(critical_level);
727
728 rt_schedule();
729
730 /* clear error number of this thread to RT_EOK */
731 if (thread->error == -RT_ETIMEOUT)
732 {
733 thread->error = RT_EOK;
734 }
735 }
736 else
737 {
738 *tick = cur_tick;
739 rt_exit_critical_safe(critical_level);
740 }
741
742 return thread->error;
743}
rt_err_t rt_timer_control(rt_timer_t timer, int cmd, void *arg)
This function will get or set some options of the timer
rt_err_t rt_timer_start(rt_timer_t timer)
This function will start the timer
rt_tick_t rt_tick_get(void)
This function will return current tick from operating system startup.
定义 clock.c:69
#define RT_TIMER_CTRL_SET_TIME
void rt_exit_critical_safe(rt_base_t critical_level)
rt_err_t rt_thread_suspend_with_flag(rt_thread_t thread, int suspend_flag)
This function will suspend the specified thread and change it to suspend state.
rt_base_t rt_enter_critical(void)
This function will lock the thread scheduler.
void rt_schedule(void)
This function will perform one scheduling. It will select one thread with the highest priority level ...
rt_uint32_t rt_tick_t
rt_err_t error

引用了 rt_thread::error, RT_ASSERT, rt_enter_critical(), rt_exit_critical_safe(), RT_NULL, RT_Object_Class_Thread, rt_object_get_type(), rt_schedule(), rt_thread_self(), rt_thread_suspend_with_flag(), rt_tick_get(), rt_timer_control(), RT_TIMER_CTRL_SET_TIME, rt_timer_start(), RT_UNINTERRUPTIBLE , 以及 rt_thread::thread_timer.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [10/18]

RTM_EXPORT ( rt_thread_delay_until )

引用了 rt_thread_delay_until().

+ 函数调用图:

◆ rt_thread_mdelay()

rt_err_t rt_thread_mdelay ( rt_int32_t ms)

This function will let current thread delay for some milliseconds.

参数
msis the delay ms time.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c754 行定义.

755{
756 rt_tick_t tick;
757
758 tick = rt_tick_from_millisecond(ms);
759
760 return _thread_sleep(tick);
761}
rt_tick_t rt_tick_from_millisecond(rt_int32_t ms)
This function will calculate the tick from millisecond.

引用了 rt_tick_from_millisecond().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [11/18]

RTM_EXPORT ( rt_thread_mdelay )

引用了 rt_thread_mdelay().

+ 函数调用图:

◆ rt_thread_control()

rt_err_t rt_thread_control ( rt_thread_t thread,
int cmd,
void * arg )

This function will control thread behaviors according to control command.

参数
threadis the specified thread to be controlled.
cmdis the control command, which includes.
         RT_THREAD_CTRL_CHANGE_PRIORITY for changing priority level of thread.

         RT_THREAD_CTRL_STARTUP for starting a thread.

         RT_THREAD_CTRL_CLOSE for delete a thread.

         RT_THREAD_CTRL_BIND_CPU for bind the thread to a CPU.
argis the argument of control command.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c787 行定义.

788{
789 /* parameter check */
790 RT_ASSERT(thread != RT_NULL);
792
793 switch (cmd)
794 {
796 {
797 rt_err_t error;
799 rt_sched_lock(&slvl);
800 error = rt_sched_thread_change_priority(thread, *(rt_uint8_t *)arg);
801 rt_sched_unlock(slvl);
802 return error;
803 }
804
806 {
807 return rt_thread_startup(thread);
808 }
809
811 {
812 rt_err_t rt_err = -RT_EINVAL;
813
815 {
816 rt_err = rt_thread_detach(thread);
817 }
818 #ifdef RT_USING_HEAP
819 else
820 {
821 rt_err = rt_thread_delete(thread);
822 }
823 #endif /* RT_USING_HEAP */
824 rt_schedule();
825 return rt_err;
826 }
827
829 {
830 rt_uint8_t cpu;
831
832 cpu = (rt_uint8_t)(rt_size_t)arg;
833 return rt_sched_thread_bind_cpu(thread, cpu);
834 }
835
836 default:
837 break;
838 }
839
840 return RT_EOK;
841}
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
#define RT_THREAD_CTRL_BIND_CPU
rt_err_t rt_thread_detach(rt_thread_t thread)
This function will detach a thread. The thread object will be removed from thread queue and detached/...
rt_err_t rt_thread_delete(rt_thread_t thread)
This function will delete a thread. The thread object will be removed from thread queue and deleted f...
#define RT_THREAD_CTRL_CHANGE_PRIORITY
#define RT_THREAD_CTRL_CLOSE
#define RT_THREAD_CTRL_STARTUP
rt_base_t rt_err_t
#define RT_TRUE
rt_ubase_t rt_size_t
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
Update priority of the target thread

引用了 rt_thread::error, RT_ASSERT, RT_NULL, RT_Object_Class_Thread, rt_object_get_type(), rt_object_is_systemobject(), rt_sched_lock(), rt_sched_thread_change_priority(), rt_sched_unlock(), rt_schedule(), RT_THREAD_CTRL_BIND_CPU, RT_THREAD_CTRL_CHANGE_PRIORITY, RT_THREAD_CTRL_CLOSE, RT_THREAD_CTRL_STARTUP, rt_thread_delete(), rt_thread_detach(), rt_thread_startup() , 以及 RT_TRUE.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [12/18]

◆ rt_thread_suspend_to_list()

rt_err_t rt_thread_suspend_to_list ( rt_thread_t thread,
rt_list_t * susp_list,
int ipc_flags,
int suspend_flag )

This function will suspend the specified thread and change it to suspend state.

注解
This function ONLY can suspend current thread itself. rt_thread_suspend(rt_thread_self());

Do not use the rt_thread_suspend to suspend other threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while sharing a resouce with other threads and occupying this resouce, starvation can occur very easily.

参数
threadthe thread to be suspended.
susp_listthe list thread enqueued to. RT_NULL if no list.
ipc_flagsis a flag for the thread object to be suspended. It determines how the thread is suspended. The flag can be ONE of the following values: RT_IPC_FLAG_PRIO The pending threads will queue in order of priority. RT_IPC_FLAG_FIFO The pending threads will queue in the first-in-first-out method (also known as first-come-first-served (FCFS) scheduling strategy). NOTE: RT_IPC_FLAG_FIFO is a non-real-time scheduling mode. It is strongly recommended to use RT_IPC_FLAG_PRIO to ensure the thread is real-time UNLESS your applications concern about the first-in-first-out principle, and you clearly understand that all threads involved in this semaphore will become non-real-time threads.
suspend_flagstatus flag of the thread to be suspended.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

enqueue thread on the push list before leaving critical region of scheduler, so we won't miss notification of async events.

在文件 thread.c897 行定义.

898{
901
902 /* parameter check */
903 RT_ASSERT(thread != RT_NULL);
905 RT_ASSERT(thread == rt_thread_self());
906
907 LOG_D("thread suspend: %s", thread->parent.name);
908
909 rt_sched_lock(&slvl);
910
913 {
914 LOG_D("thread suspend: thread disorder, 0x%2x", thread->stat);
915 rt_sched_unlock(slvl);
916 return -RT_ERROR;
917 }
918
919 if (stat == RT_THREAD_RUNNING)
920 {
921 /* not suspend running status thread on other core */
922 RT_ASSERT(thread == rt_thread_self());
923 }
924
925#ifdef RT_USING_SMART
926 if (thread->lwp)
927 {
928 rt_sched_unlock(slvl);
929
930 /* check pending signals for thread before suspend */
931 if (lwp_thread_signal_suspend_check(thread, suspend_flag) == 0)
932 {
933 /* not to suspend */
934 return -RT_EINTR;
935 }
936
937 rt_sched_lock(&slvl);
938 if (stat == RT_THREAD_READY)
939 {
941
942 if (stat != RT_THREAD_READY)
943 {
944 /* status updated while we check for signal */
945 rt_sched_unlock(slvl);
946 return -RT_ERROR;
947 }
948 }
949 }
950#endif
951
952 /* change thread stat */
953 rt_sched_remove_thread(thread);
954 _thread_set_suspend_state(thread, suspend_flag);
955
956 if (susp_list)
957 {
962 rt_susp_list_enqueue(susp_list, thread, ipc_flags);
963 }
964
965 /* stop thread timer anyway */
967
968 rt_sched_unlock(slvl);
969
970 RT_OBJECT_HOOK_CALL(rt_thread_suspend_hook, (thread));
971 return RT_EOK;
972}
rt_err_t rt_susp_list_enqueue(rt_list_t *susp_list, rt_thread_t thread, int ipc_flags)
Add a thread to the suspend list
定义 ipc.c:241
#define RT_OBJECT_HOOK_CALL(func, argv)
#define RT_THREAD_READY
#define RT_THREAD_RUNNING
rt_err_t rt_sched_thread_timer_stop(struct rt_thread *thread)

引用了 LOG_D, rt_object::name, rt_thread::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Thread, rt_object_get_type(), RT_OBJECT_HOOK_CALL, rt_sched_lock(), rt_sched_thread_get_stat(), rt_sched_thread_timer_stop(), rt_sched_unlock(), rt_susp_list_enqueue(), RT_THREAD_READY, RT_THREAD_RUNNING, rt_thread_self() , 以及 stat().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [13/18]

RTM_EXPORT ( rt_thread_suspend_to_list )

引用了 rt_thread_suspend_to_list().

+ 函数调用图:

◆ rt_thread_suspend_with_flag()

rt_err_t rt_thread_suspend_with_flag ( rt_thread_t thread,
int suspend_flag )

This function will suspend the specified thread and change it to suspend state.

注解
This function ONLY can suspend current thread itself. rt_thread_suspend(rt_thread_self());

Do not use the rt_thread_suspend to suspend other threads. You have no way of knowing what code a thread is executing when you suspend it. If you suspend a thread while sharing a resouce with other threads and occupying this resouce, starvation can occur very easily.

参数
threadthe thread to be suspended.
suspend_flagstatus flag of the thread to be suspended.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

在文件 thread.c991 行定义.

992{
993 return rt_thread_suspend_to_list(thread, RT_NULL, 0, suspend_flag);
994}
rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int ipc_flags, int suspend_flag)
This function will suspend the specified thread and change it to suspend state.

引用了 RT_NULL , 以及 rt_thread_suspend_to_list().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [14/18]

引用了 rt_thread_suspend_with_flag().

+ 函数调用图:

◆ rt_thread_suspend()

rt_err_t rt_thread_suspend ( rt_thread_t thread)

在文件 thread.c997 行定义.

998{
1000}

引用了 rt_thread_suspend_with_flag() , 以及 RT_UNINTERRUPTIBLE.

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [15/18]

RTM_EXPORT ( rt_thread_suspend )

引用了 rt_thread_suspend().

+ 函数调用图:

◆ rt_thread_resume()

rt_err_t rt_thread_resume ( rt_thread_t thread)

This function will resume a thread and put it to system ready queue.

参数
threadis the thread to be resumed.
返回
Return the operation status. If the return value is RT_EOK, the function is successfully executed. If the return value is any other values, it means this operation failed.

RT_ESCHEDLOCKED indicates that the current thread is in a critical section, rather than 'thread' can't be resumed. Therefore, we can ignore this error.

在文件 thread.c1011 行定义.

1012{
1014 rt_err_t error;
1015
1016 /* parameter check */
1017 RT_ASSERT(thread != RT_NULL);
1019
1020 LOG_D("thread resume: %s", thread->parent.name);
1021
1022 rt_sched_lock(&slvl);
1023
1024 error = rt_sched_thread_ready(thread);
1025
1026 if (!error)
1027 {
1028 error = rt_sched_unlock_n_resched(slvl);
1029
1034 if (error == -RT_ESCHEDLOCKED)
1035 {
1036 error = RT_EOK;
1037 }
1038 }
1039 else
1040 {
1041 rt_sched_unlock(slvl);
1042 }
1043
1044 RT_OBJECT_HOOK_CALL(rt_thread_resume_hook, (thread));
1045
1046 return error;
1047}
rt_err_t rt_sched_thread_ready(struct rt_thread *thread)

引用了 rt_thread::error, LOG_D, rt_object::name, rt_thread::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Thread, rt_object_get_type(), RT_OBJECT_HOOK_CALL, rt_sched_lock(), rt_sched_thread_ready(), rt_sched_unlock() , 以及 rt_sched_unlock_n_resched().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [16/18]

RTM_EXPORT ( rt_thread_resume )

引用了 RT_NULL, RT_Object_Class_Thread , 以及 rt_thread_resume().

+ 函数调用图:

◆ rt_thread_find()

rt_thread_t rt_thread_find ( char * name)

This function will find the specified thread.

注解
Please don't invoke this function in interrupt status.
参数
nameis the name of thread finding.
返回
If the return value is a rt_thread structure pointer, the function is successfully executed. If the return value is RT_NULL, it means this operation failed.

在文件 thread.c1108 行定义.

1109{
1111}
rt_object_t rt_object_find(const char *name, rt_uint8_t type)
This function will find specified name object from object container.

引用了 RT_Object_Class_Thread , 以及 rt_object_find().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [17/18]

RTM_EXPORT ( rt_thread_find )

引用了 rt_thread_find().

+ 函数调用图:

◆ rt_thread_get_name()

rt_err_t rt_thread_get_name ( rt_thread_t thread,
char * name,
rt_uint8_t name_size )

This function will return the name of the specified thread

注解
Please don't invoke this function in interrupt status
参数
threadthe thread to retrieve thread name
namebuffer to store the thread name string
name_sizemaximum size of the buffer to store the thread name
返回
If the return value is RT_EOK, the function is successfully executed If the return value is -RT_EINVAL, it means this operation failed

在文件 thread.c1127 行定义.

1128{
1129 return (thread == RT_NULL) ? -RT_EINVAL : rt_object_get_name(&thread->parent, name, name_size);
1130}
rt_err_t rt_object_get_name(rt_object_t object, char *name, rt_uint8_t name_size)
This function will return the name of the specified object container

引用了 rt_thread::parent, RT_NULL , 以及 rt_object_get_name().

+ 函数调用图:
+ 这是这个函数的调用关系图:

◆ RTM_EXPORT() [18/18]

RTM_EXPORT ( rt_thread_get_name )

引用了 rt_thread_get_name().

+ 函数调用图:

◆ rt_thread_suspend_sethook()

void rt_thread_suspend_sethook ( void(* hook )(rt_thread_t thread))

◆ rt_thread_resume_sethook()

void rt_thread_resume_sethook ( void(* hook )(rt_thread_t thread))

◆ RT_OBJECT_HOOKLIST_DECLARE()

RT_OBJECT_HOOKLIST_DECLARE ( rt_thread_inited_hookproto_t ,
rt_thread_inited  )

◆ rt_thread_idle_init()

void rt_thread_idle_init ( void )

This function will initialize idle thread, then start it.

注解
this function must be invoked when system init.

在文件 idle.c171 行定义.

172{
173 rt_ubase_t i;
174#if RT_NAME_MAX > 0
175 char idle_thread_name[RT_NAME_MAX];
176#endif /* RT_NAME_MAX > 0 */
177
178#ifdef RT_USING_IDLE_HOOK
179 rt_spin_lock_init(&_hook_spinlock);
180#endif
181
182 for (i = 0; i < _CPUS_NR; i++)
183 {
184#if RT_NAME_MAX > 0
185 rt_snprintf(idle_thread_name, RT_NAME_MAX, "tidle%d", i);
186#endif /* RT_NAME_MAX > 0 */
187 rt_thread_init(&idle_thread[i],
188#if RT_NAME_MAX > 0
189 idle_thread_name,
190#else
191 "tidle",
192#endif /* RT_NAME_MAX > 0 */
193 idle_thread_entry,
194 RT_NULL,
195 &idle_thread_stack[i][0],
196 sizeof(idle_thread_stack[i]),
197 RT_THREAD_PRIORITY_MAX - 1,
198 32);
199#ifdef RT_USING_SMP
200 rt_thread_control(&idle_thread[i], RT_THREAD_CTRL_BIND_CPU, (void*)i);
201#endif /* RT_USING_SMP */
202
203 /* update */
204 rt_cpu_index(i)->idle_thread = &idle_thread[i];
205
206 /* startup */
207 rt_thread_startup(&idle_thread[i]);
208 }
209}
struct rt_cpu * rt_cpu_index(int index)
This fucntion will return the cpu object corresponding to index.
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
rt_err_t rt_thread_control(rt_thread_t thread, int cmd, void *arg)
This function will control thread behaviors according to control command.
rt_err_t rt_thread_init(struct rt_thread *thread, const char *name, void(*entry)(void *parameter), void *parameter, void *stack_start, rt_uint32_t stack_size, rt_uint8_t priority, rt_uint32_t tick)
This function will initialize a thread. It's used to initialize a static thread object.
#define _CPUS_NR
定义 idle.c:45
rt_uint32_t rt_ubase_t
struct rt_thread * idle_thread

引用了 _CPUS_NR, rt_cpu::idle_thread, rt_cpu_index(), RT_NULL, rt_spin_lock_init(), rt_thread_control(), RT_THREAD_CTRL_BIND_CPU, rt_thread_init() , 以及 rt_thread_startup().

+ 函数调用图:

◆ rt_thread_idle_sethook()

rt_err_t rt_thread_idle_sethook ( void(* hook )(void))

◆ rt_thread_idle_delhook()

rt_err_t rt_thread_idle_delhook ( void(* hook )(void))

delete the idle hook on hook list.

参数
hookthe specified hook function.
返回
RT_EOK: delete OK. -RT_ENOSYS: hook was not found.

在文件 idle.c101 行定义.

102{
103 rt_size_t i;
104 rt_err_t ret = -RT_ENOSYS;
105 rt_base_t level;
106
107 level = rt_spin_lock_irqsave(&_hook_spinlock);
108
109 for (i = 0; i < RT_IDLE_HOOK_LIST_SIZE; i++)
110 {
111 if (idle_hook_list[i] == hook)
112 {
113 idle_hook_list[i] = RT_NULL;
114 ret = RT_EOK;
115 break;
116 }
117 }
118
119 rt_spin_unlock_irqrestore(&_hook_spinlock, level);
120
121 return ret;
122}
rt_base_t rt_spin_lock_irqsave(struct rt_spinlock *lock)
This function will disable the local interrupt and then lock the spinlock, will lock the thread sched...
void rt_spin_unlock_irqrestore(struct rt_spinlock *lock, rt_base_t level)
This function will unlock the spinlock and then restore current cpu interrupt status,...
#define RT_IDLE_HOOK_LIST_SIZE

引用了 RT_IDLE_HOOK_LIST_SIZE, RT_NULL, rt_spin_lock_irqsave() , 以及 rt_spin_unlock_irqrestore().

+ 函数调用图:

◆ rt_thread_idle_gethandler()

rt_thread_t rt_thread_idle_gethandler ( void )

This function will get the handler of the idle thread.

在文件 idle.c214 行定义.

215{
216 int id = rt_cpu_get_id();
217
218 return (rt_thread_t)(&idle_thread[id]);
219}
#define rt_cpu_get_id()

引用了 rt_cpu_get_id.

◆ rt_system_scheduler_init()

void rt_system_scheduler_init ( void )

This function will initialize the system scheduler.

在文件 scheduler_mp.c403 行定义.

404{
405 int cpu;
406 rt_base_t offset;
407
408 LOG_D("start scheduler: max priority 0x%02x",
409 RT_THREAD_PRIORITY_MAX);
410
411 rt_spin_lock_init(&_mp_scheduler_lock);
412
413 for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
414 {
416 }
417
418 for (cpu = 0; cpu < RT_CPUS_NR; cpu++)
419 {
420 struct rt_cpu *pcpu = rt_cpu_index(cpu);
421 for (offset = 0; offset < RT_THREAD_PRIORITY_MAX; offset ++)
422 {
423 rt_list_init(&pcpu->priority_table[offset]);
424 }
425
426 pcpu->irq_switch_flag = 0;
427 pcpu->current_priority = RT_THREAD_PRIORITY_MAX - 1;
428 pcpu->current_thread = RT_NULL;
429 pcpu->priority_group = 0;
430
431#if RT_THREAD_PRIORITY_MAX > 32
432 rt_memset(pcpu->ready_table, 0, sizeof(pcpu->ready_table));
433#endif /* RT_THREAD_PRIORITY_MAX > 32 */
434
435#ifdef RT_USING_SMART
436 rt_spin_lock_init(&(pcpu->spinlock));
437#endif
438 }
439
440 /* initialize ready priority group */
441 rt_thread_ready_priority_group = 0;
442
443#if RT_THREAD_PRIORITY_MAX > 32
444 /* initialize ready table */
445 rt_memset(rt_thread_ready_table, 0, sizeof(rt_thread_ready_table));
446#endif /* RT_THREAD_PRIORITY_MAX > 32 */
447}
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
rt_list_t rt_thread_priority_table[RT_THREAD_PRIORITY_MAX]

引用了 rt_cpu::current_thread, LOG_D, rt_cpu_index(), rt_list_init(), RT_NULL, rt_spin_lock_init() , 以及 rt_thread_priority_table.

+ 函数调用图:

◆ rt_system_scheduler_start()

void rt_system_scheduler_start ( void )

This function will startup the scheduler. It will select one thread with the highest priority level, then switch to it.

legacy rt_cpus_lock. some bsp codes still use it as for it's critical region. Since scheduler is never touching this, here we just release it on the entry.

for the accessing of the scheduler context. Noted that we don't have current_thread at this point

在文件 scheduler_mp.c453 行定义.

454{
455 struct rt_thread *to_thread;
456 rt_ubase_t highest_ready_priority;
457
464
465 /* ISR will corrupt the coherency of running frame */
467
472 _fast_spin_lock(&_mp_scheduler_lock);
473
474 /* get the thread scheduling to */
475 to_thread = _scheduler_get_highest_priority_thread(&highest_ready_priority);
476 RT_ASSERT(to_thread);
477
478 /* to_thread is picked to running on current core, so remove it from ready queue */
479 _sched_remove_thread_locked(to_thread);
480
481 /* dedigate current core to `to_thread` */
482 RT_SCHED_CTX(to_thread).oncpu = rt_hw_cpu_id();
483 RT_SCHED_CTX(to_thread).stat = RT_THREAD_RUNNING;
484
485 LOG_D("[cpu#%d] switch to priority#%d thread:%.*s(sp:0x%08x)",
486 rt_hw_cpu_id(), RT_SCHED_PRIV(to_thread).current_priority,
487 RT_NAME_MAX, to_thread->parent.name, to_thread->sp);
488
489 _fast_spin_unlock(&_mp_scheduler_lock);
490
491 /* switch to new thread */
492 rt_hw_context_switch_to((rt_ubase_t)&to_thread->sp, to_thread);
493
494 /* never come back */
495}
rt_hw_spinlock_t _cpus_lock
void rt_hw_context_switch_to(rt_ubase_t to)
int rt_hw_cpu_id(void)
#define rt_hw_spin_unlock(lock)
定义 rthw.h:236
#define RT_SCHED_PRIV(thread)
rt_inline void _fast_spin_lock(struct rt_spinlock *lock)
rt_inline void _fast_spin_unlock(struct rt_spinlock *lock)
void * sp

引用了 _cpus_lock, _fast_spin_lock(), _fast_spin_unlock(), rt_cpu::current_thread, LOG_D, rt_object::name, rt_thread::parent, RT_ASSERT, rt_cpu_self(), rt_hw_context_switch_to(), rt_hw_cpu_id(), rt_hw_local_irq_disable, rt_hw_spin_unlock, RT_SCHED_CTX, RT_SCHED_PRIV, RT_THREAD_RUNNING , 以及 rt_thread::sp.

+ 函数调用图:

◆ rt_schedule()

void rt_schedule ( void )

This function will perform one scheduling. It will select one thread with the highest priority level in global ready queue or local ready queue, then switch to it.

注解
this function is implemented in both scheduler_up.c and scheduler_mp.c.
+ 这是这个函数的调用关系图:

◆ rt_scheduler_do_irq_switch()

void rt_scheduler_do_irq_switch ( void * context)

This function checks whether a scheduling is needed after an IRQ context switching. If yes, it will select one thread with the highest priority level, and then switch to it.

参数
contextis the context to be switched to.
注解
this function is only implemented in scheduler_mp.c.

◆ rt_enter_critical()

void rt_enter_critical ( void )

This function will lock the thread scheduler.

注解
this function is implemented in both scheduler_up.c and scheduler_mp.c.
+ 这是这个函数的调用关系图:

◆ rt_exit_critical()

void rt_exit_critical ( void )

This function will unlock the thread scheduler.

注解
this function is implemented in both scheduler_up.c and scheduler_mp.c.
+ 这是这个函数的调用关系图:

◆ rt_exit_critical_safe()

void rt_exit_critical_safe ( rt_base_t critical_level)
+ 这是这个函数的调用关系图:

◆ rt_critical_level()

rt_uint16_t rt_critical_level ( void )

Get the scheduler lock level.

返回
the level of the scheduler lock. 0 means unlocked.
注解
this function is implemented in both scheduler_up.c and scheduler_mp.c.
+ 这是这个函数的调用关系图:

◆ rt_scheduler_sethook()

void rt_scheduler_sethook ( void(* hook )(rt_thread_t from, rt_thread_t to))

◆ rt_scheduler_switch_sethook()

void rt_scheduler_switch_sethook ( void(* hook )(struct rt_thread *tid))

◆ rt_scheduler_ipi_handler()

void rt_scheduler_ipi_handler ( int vector,
void * param )

This function will handle IPI interrupt and do a scheduling in system.

参数
vectoris the number of IPI interrupt for system scheduling.
paramis not used, and can be set to RT_NULL.
注解
this function should be invoke or register as ISR in BSP.
this function is only implemented in scheduler_mp.c.

◆ rt_schedule_insert_thread()

void rt_schedule_insert_thread ( struct rt_thread * thread)

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.

参数
threadis the thread to be inserted.
注解
Please do not invoke this function in user application.
this function is implemented in both scheduler_up.c and scheduler_mp.c.

◆ rt_schedule_remove_thread()

void rt_schedule_remove_thread ( struct rt_thread * thread)

This function will remove a thread from system ready queue.

参数
threadis the thread to be removed.
注解
Please do not invoke this function in user application.
this function is implemented in both scheduler_up.c and scheduler_mp.c.