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

专题

 Semaphore
 
 Mutex
 
 Event
 
 Mailbox
 
 Messagequeue
 

结构体

struct  rt_ipc_object
 

宏定义

#define RT_IPC_FLAG_FIFO   0x00
 
#define RT_IPC_FLAG_PRIO   0x01
 
#define RT_IPC_CMD_UNKNOWN   0x00
 
#define RT_IPC_CMD_RESET   0x01
 
#define RT_IPC_CMD_GET_STATE   0x02
 
#define RT_IPC_CMD_SET_VLIMIT   0x03
 
#define RT_WAITING_FOREVER   -1
 
#define RT_WAITING_NO   0
 
#define RT_THREAD_RESUME_RES_THR_ERR   (-1)
 

函数

rt_inline rt_err_t _ipc_object_init (struct rt_ipc_object *ipc)
 
struct rt_threadrt_susp_list_dequeue (rt_list_t *susp_list, rt_err_t thread_error)
 
rt_err_t rt_susp_list_resume_all (rt_list_t *susp_list, rt_err_t thread_error)
 
rt_err_t rt_susp_list_resume_all_irq (rt_list_t *susp_list, rt_err_t thread_error, struct rt_spinlock *lock)
 
rt_err_t rt_susp_list_enqueue (rt_list_t *susp_list, rt_thread_t thread, int ipc_flags)
 
void rt_susp_list_print (rt_list_t *list)
 
rt_inline rt_uint8_t _mutex_update_priority (struct rt_mutex *mutex)
 
rt_inline rt_uint8_t _thread_get_mutex_priority (struct rt_thread *thread)
 
rt_inline void _thread_update_priority (struct rt_thread *thread, rt_uint8_t priority, int suspend_flag)
 
rt_err_t rt_thread_suspend_to_list (rt_thread_t thread, rt_list_t *susp_list, int ipc_flags, int suspend_flag)
 
void rt_thread_defunct_init (void)
 
void rt_thread_defunct_enqueue (rt_thread_t thread)
 
rt_thread_t rt_thread_defunct_dequeue (void)
 
void rt_defunct_execute (void)
 
void rt_spin_lock_init (struct rt_spinlock *lock)
 
void rt_spin_lock (struct rt_spinlock *lock)
 
void rt_spin_unlock (struct rt_spinlock *lock)
 
rt_base_t rt_spin_lock_irqsave (struct rt_spinlock *lock)
 
void rt_spin_unlock_irqrestore (struct rt_spinlock *lock, rt_base_t level)
 

详细描述

inter-thread communication

RT-Thread operating system supports the traditional semaphore and mutex.

Moreover, the blocked queue for thread to obtain semaphore or mutex can be sorted by priority or FIFO. There are two flags to indicate this mechanism.

RT-Thread operating systems supports event/fast event, mail box and message queue.

宏定义说明

◆ RT_IPC_FLAG_FIFO

#define RT_IPC_FLAG_FIFO   0x00

IPC flags and control command definitions FIFOed IPC. Inter-Thread Communication.

在文件 rtdef.h972 行定义.

◆ RT_IPC_FLAG_PRIO

#define RT_IPC_FLAG_PRIO   0x01

PRIOed IPC. Inter-Thread Communication.

在文件 rtdef.h973 行定义.

◆ RT_IPC_CMD_UNKNOWN

#define RT_IPC_CMD_UNKNOWN   0x00

unknown IPC command

在文件 rtdef.h975 行定义.

◆ RT_IPC_CMD_RESET

#define RT_IPC_CMD_RESET   0x01

reset IPC object

在文件 rtdef.h976 行定义.

◆ RT_IPC_CMD_GET_STATE

#define RT_IPC_CMD_GET_STATE   0x02

get the state of IPC object

在文件 rtdef.h977 行定义.

◆ RT_IPC_CMD_SET_VLIMIT

#define RT_IPC_CMD_SET_VLIMIT   0x03

set max limit value of IPC value

在文件 rtdef.h978 行定义.

◆ RT_WAITING_FOREVER

#define RT_WAITING_FOREVER   -1

Block forever until get resource.

在文件 rtdef.h980 行定义.

◆ RT_WAITING_NO

#define RT_WAITING_NO   0

Non-block.

在文件 rtdef.h981 行定义.

◆ RT_THREAD_RESUME_RES_THR_ERR

#define RT_THREAD_RESUME_RES_THR_ERR   (-1)

在文件 rtthread.h401 行定义.

函数说明

◆ _ipc_object_init()

rt_inline rt_err_t _ipc_object_init ( struct rt_ipc_object * ipc)

This function will initialize an IPC object, such as semaphore, mutex, messagequeue and mailbox.

注解
Executing this function will complete an initialization of the suspend thread list of the ipc object.
参数
ipcis a pointer to the IPC object.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. When the return value is any other values, it means the initialization failed.
警告
This function can be called from all IPC initialization and creation.

在文件 ipc.c82 行定义.

83{
84 /* initialize ipc object */
86
87 return RT_EOK;
88}
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
rt_list_t suspend_thread

引用了 rt_list_init() , 以及 rt_ipc_object::suspend_thread.

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

◆ rt_susp_list_dequeue()

struct rt_thread * rt_susp_list_dequeue ( rt_list_t * susp_list,
rt_err_t thread_error )

Dequeue a thread from suspended list and set it to ready. The 2 are taken as an atomic operation, so if a thread is returned, it's resumed by us, not any other threads or async events. This is useful if a consumer may be resumed by timeout, signals... besides its producer.

参数
susp_listthe list thread dequeued from. RT_NULL if no list.
thread_errorthread error number of the resuming thread. A negative value in this set will be discarded, and thread error will not be changed.
返回
struct rt_thread * RT_NULL if failed, otherwise the thread resumed

在文件 ipc.c105 行定义.

106{
108 rt_thread_t thread;
109 rt_err_t error;
110
112 RT_ASSERT(susp_list != RT_NULL);
113
114 rt_sched_lock(&slvl);
115 if (!rt_list_isempty(susp_list))
116 {
117 thread = RT_THREAD_LIST_NODE_ENTRY(susp_list->next);
118 error = rt_sched_thread_ready(thread);
119
120 if (error)
121 {
122 LOG_D("%s [error:%d] failed to resume thread:%p from suspended list",
123 __func__, error, thread);
124
125 thread = RT_NULL;
126 }
127 else
128 {
129 /* thread error should not be a negative value */
130 if (thread_error >= 0)
131 {
132 /* set thread error code to notified resuming thread */
133 thread->error = thread_error;
134 }
135 }
136 }
137 else
138 {
139 thread = RT_NULL;
140 }
141 rt_sched_unlock(slvl);
142
143 LOG_D("resume thread:%s\n", thread->parent.name);
144
145 return thread;
146}
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
#define RT_ASSERT(EX)
struct rt_thread * rt_thread_t
#define LOG_D(...)
#define RT_SCHED_DEBUG_IS_UNLOCKED
#define RT_THREAD_LIST_NODE_ENTRY(node)
rt_ubase_t rt_sched_lock_level_t
rt_base_t rt_err_t
#define RT_NULL
rt_err_t rt_sched_thread_ready(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)
struct rt_list_node * next
const char * name
rt_err_t error
struct rt_object parent

引用了 rt_thread::error, LOG_D, rt_object::name, rt_list_node::next, rt_thread::parent, RT_ASSERT, rt_list_isempty(), RT_NULL, RT_SCHED_DEBUG_IS_UNLOCKED, rt_sched_lock(), rt_sched_thread_ready(), rt_sched_unlock() , 以及 RT_THREAD_LIST_NODE_ENTRY.

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

◆ rt_susp_list_resume_all()

rt_err_t rt_susp_list_resume_all ( rt_list_t * susp_list,
rt_err_t thread_error )

This function will resume all suspended threads in the IPC object list, including the suspended list of IPC object, and private list of mailbox etc.

注解
This function will resume all threads in the IPC object list. By contrast, the rt_ipc_list_resume() function will resume a suspended thread in the list of a IPC object.
参数
susp_listis a pointer to a suspended thread list of the IPC object.
thread_errorthread error number of the resuming thread. A negative value in this set will be discarded, and thread error will not be changed.
返回
Return the operation status. When the return value is RT_EOK, the function is successfully executed. When the return value is any other values, it means this operation failed.

在文件 ipc.c165 行定义.

166{
167 struct rt_thread *thread;
168
170
171 /* wakeup all suspended threads */
172 thread = rt_susp_list_dequeue(susp_list, thread_error);
173 while (thread)
174 {
175 /*
176 * resume NEXT thread
177 * In rt_thread_resume function, it will remove current thread from
178 * suspended list
179 */
180 thread = rt_susp_list_dequeue(susp_list, thread_error);
181 }
182
183 return RT_EOK;
184}
struct rt_thread * rt_susp_list_dequeue(rt_list_t *susp_list, rt_err_t thread_error)
Dequeue a thread from suspended list and set it to ready. The 2 are taken as an atomic operation,...
定义 ipc.c:105

引用了 RT_SCHED_DEBUG_IS_UNLOCKED , 以及 rt_susp_list_dequeue().

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

◆ rt_susp_list_resume_all_irq()

rt_err_t rt_susp_list_resume_all_irq ( rt_list_t * susp_list,
rt_err_t thread_error,
struct rt_spinlock * lock )

This function will resume all suspended threads in the IPC object list, including the suspended list of IPC object, and private list of mailbox etc. A lock is passing and hold while operating.

注解
This function will resume all threads in the IPC object list. By contrast, the rt_ipc_list_resume() function will resume a suspended thread in the list of a IPC object.
参数
susp_listis a pointer to a suspended thread list of the IPC object.
thread_errorthread error number of the resuming thread. A negative value in this set will be discarded, and thread error will not be changed.
lockthe lock to be held while operating susp_list
返回
Return the operation status. When the return value is RT_EOK, the function is successfully executed. When the return value is any other values, it means this operation failed.

在文件 ipc.c204 行定义.

207{
208 struct rt_thread *thread;
209 rt_base_t level;
210
212
213 do
214 {
215 level = rt_spin_lock_irqsave(lock);
216
217 /*
218 * resume NEXT thread
219 * In rt_thread_resume function, it will remove current thread from
220 * suspended list
221 */
222 thread = rt_susp_list_dequeue(susp_list, thread_error);
223
224 rt_spin_unlock_irqrestore(lock, level);
225 }
226 while (thread);
227
228 return RT_EOK;
229}
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,...
rt_int32_t rt_base_t

引用了 RT_SCHED_DEBUG_IS_UNLOCKED, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_susp_list_dequeue().

+ 函数调用图:

◆ rt_susp_list_enqueue()

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

注解
Caller must hold the scheduler lock
参数
susp_listthe list thread enqueued to
threadthe suspended thread
ipc_flagsthe pattern of suspend list
返回
RT_EOK on succeed, otherwise a failure

在文件 ipc.c241 行定义.

242{
244
245 switch (ipc_flags)
246 {
247 case RT_IPC_FLAG_FIFO:
248 rt_list_insert_before(susp_list, &RT_THREAD_LIST_NODE(thread));
249 break; /* RT_IPC_FLAG_FIFO */
250
251 case RT_IPC_FLAG_PRIO:
252 {
253 struct rt_list_node *n;
254 struct rt_thread *sthread;
255
256 /* find a suitable position */
257 for (n = susp_list->next; n != susp_list; n = n->next)
258 {
259 sthread = RT_THREAD_LIST_NODE_ENTRY(n);
260
261 /* find out */
263 {
264 /* insert this thread before the sthread */
266 break;
267 }
268 }
269
270 /*
271 * not found a suitable position,
272 * append to the end of suspend_thread list
273 */
274 if (n == susp_list)
275 rt_list_insert_before(susp_list, &RT_THREAD_LIST_NODE(thread));
276 }
277 break;/* RT_IPC_FLAG_PRIO */
278
279 default:
280 RT_ASSERT(0);
281 break;
282 }
283
284 return RT_EOK;
285}
#define RT_IPC_FLAG_FIFO
#define RT_IPC_FLAG_PRIO
rt_inline void rt_list_insert_before(rt_list_t *l, rt_list_t *n)
insert a node before a list
#define RT_SCHED_DEBUG_IS_LOCKED
#define RT_THREAD_LIST_NODE(thread)
rt_uint8_t rt_sched_thread_get_curr_prio(struct rt_thread *thread)

引用了 rt_list_node::next, RT_ASSERT, RT_IPC_FLAG_FIFO, RT_IPC_FLAG_PRIO, rt_list_insert_before(), RT_SCHED_DEBUG_IS_LOCKED, rt_sched_thread_get_curr_prio(), RT_THREAD_LIST_NODE , 以及 RT_THREAD_LIST_NODE_ENTRY.

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

◆ rt_susp_list_print()

void rt_susp_list_print ( rt_list_t * list)

Print thread on suspend list to system console

Suspend list - A basic building block for IPC primitives which interacts with scheduler directly. Its API is similar to a FIFO list.

Note: don't use in application codes directly

在文件 ipc.c290 行定义.

291{
292#ifdef RT_USING_CONSOLE
294 struct rt_thread *thread;
295 struct rt_list_node *node;
296
297 rt_sched_lock(&slvl);
298
299 for (node = list->next; node != list; node = node->next)
300 {
301 thread = RT_THREAD_LIST_NODE_ENTRY(node);
302 rt_kprintf("%.*s", RT_NAME_MAX, thread->parent.name);
303
304 if (node->next != list)
305 rt_kprintf("/");
306 }
307
308 rt_sched_unlock(slvl);
309#else
310 (void)list;
311#endif
312}
#define rt_kprintf(...)

引用了 rt_object::name, rt_list_node::next, rt_thread::parent, rt_kprintf, rt_sched_lock(), rt_sched_unlock() , 以及 RT_THREAD_LIST_NODE_ENTRY.

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

◆ _mutex_update_priority()

rt_inline rt_uint8_t _mutex_update_priority ( struct rt_mutex * mutex)

在文件 ipc.c827 行定义.

828{
829 struct rt_thread *thread;
830
832 {
835 }
836 else
837 {
838 mutex->priority = 0xff;
839 }
840
841 return mutex->priority;
842}
struct rt_ipc_object parent
rt_uint8_t priority

引用了 rt_list_node::next, rt_mutex::parent, rt_mutex::priority, rt_list_isempty(), rt_sched_thread_get_curr_prio(), RT_THREAD_LIST_NODE_ENTRY , 以及 rt_ipc_object::suspend_thread.

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

◆ _thread_get_mutex_priority()

rt_inline rt_uint8_t _thread_get_mutex_priority ( struct rt_thread * thread)

在文件 ipc.c845 行定义.

846{
847 rt_list_t *node = RT_NULL;
848 struct rt_mutex *mutex = RT_NULL;
850
851 rt_list_for_each(node, &(thread->taken_object_list))
852 {
853 mutex = rt_list_entry(node, struct rt_mutex, taken_list);
854 rt_uint8_t mutex_prio = mutex->priority;
855 /* prio at least be priority ceiling */
856 mutex_prio = mutex_prio < mutex->ceiling_priority ? mutex_prio : mutex->ceiling_priority;
857
858 if (priority > mutex_prio)
859 {
860 priority = mutex_prio;
861 }
862 }
863
864 return priority;
865}
#define rt_list_for_each(pos, head)
#define rt_list_entry(node, type, member)
get the struct for this entry
unsigned char rt_uint8_t
struct rt_list_node rt_list_t
rt_uint8_t rt_sched_thread_get_init_prio(struct rt_thread *thread)
rt_uint8_t ceiling_priority
rt_list_t taken_list
rt_list_t taken_object_list

引用了 rt_mutex::ceiling_priority, rt_mutex::priority, rt_list_entry, rt_list_for_each, RT_NULL, rt_sched_thread_get_init_prio(), rt_mutex::taken_list , 以及 rt_thread::taken_object_list.

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

◆ _thread_update_priority()

rt_inline void _thread_update_priority ( struct rt_thread * thread,
rt_uint8_t priority,
int suspend_flag )

在文件 ipc.c868 行定义.

869{
870 rt_err_t ret = -RT_ERROR;
871 struct rt_object* pending_obj = RT_NULL;
872
873 LOG_D("thread:%s priority -> %d", thread->parent.name, priority);
874
875 /* change priority of the thread */
876 ret = rt_sched_thread_change_priority(thread, priority);
877
878 while ((ret == RT_EOK) && rt_sched_thread_is_suspended(thread))
879 {
880 /* whether change the priority of taken mutex */
881 pending_obj = thread->pending_object;
882
883 if (pending_obj && rt_object_get_type(pending_obj) == RT_Object_Class_Mutex)
884 {
885 rt_uint8_t mutex_priority = 0xff;
886 struct rt_mutex* pending_mutex = (struct rt_mutex *)pending_obj;
887
888 /* re-insert thread to suspended thread list to resort priority list */
890
892 &(pending_mutex->parent.suspend_thread), thread,
893 pending_mutex->parent.parent.flag);
894 if (ret == RT_EOK)
895 {
896 /* update priority */
897 _mutex_update_priority(pending_mutex);
898 /* change the priority of mutex owner thread */
899 LOG_D("mutex: %s priority -> %d", pending_mutex->parent.parent.name,
900 pending_mutex->priority);
901
902 mutex_priority = _thread_get_mutex_priority(pending_mutex->owner);
903 if (mutex_priority != rt_sched_thread_get_curr_prio(pending_mutex->owner))
904 {
905 thread = pending_mutex->owner;
906
907 ret = rt_sched_thread_change_priority(thread, mutex_priority);
908 }
909 else
910 {
911 ret = -RT_ERROR;
912 }
913 }
914 }
915 else
916 {
917 ret = -RT_ERROR;
918 }
919 }
920}
rt_inline rt_uint8_t _thread_get_mutex_priority(struct rt_thread *thread)
定义 ipc.c:845
rt_inline rt_uint8_t _mutex_update_priority(struct rt_mutex *mutex)
定义 ipc.c:827
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
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.
@ RT_Object_Class_Mutex
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
rt_err_t rt_sched_thread_change_priority(struct rt_thread *thread, rt_uint8_t priority)
Update priority of the target thread
rt_uint8_t rt_sched_thread_is_suspended(struct rt_thread *thread)
struct rt_object parent
struct rt_thread * owner
rt_uint8_t flag
rt_object_t pending_object

引用了 _mutex_update_priority(), _thread_get_mutex_priority(), rt_object::flag, LOG_D, rt_object::name, rt_mutex::owner, rt_ipc_object::parent, rt_mutex::parent, rt_thread::parent, rt_thread::pending_object, rt_mutex::priority, rt_list_remove(), RT_NULL, RT_Object_Class_Mutex, rt_object_get_type(), rt_sched_thread_change_priority(), rt_sched_thread_get_curr_prio(), rt_sched_thread_is_suspended(), rt_susp_list_enqueue(), RT_THREAD_LIST_NODE , 以及 rt_ipc_object::suspend_thread.

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

◆ 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}
int stat(const char *file, struct stat *buf)
#define RT_OBJECT_HOOK_CALL(func, argv)
struct rt_object * rt_object_t
@ RT_Object_Class_Thread
#define RT_THREAD_READY
rt_thread_t rt_thread_self(void)
This function will return self thread object.
#define RT_THREAD_RUNNING
rt_uint8_t rt_sched_thread_get_stat(struct rt_thread *thread)
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().

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

◆ rt_thread_defunct_init()

void rt_thread_defunct_init ( void )

在文件 defunct.c157 行定义.

158{
159 RT_ASSERT(RT_THREAD_PRIORITY_MAX > 2);
160
161 rt_spin_lock_init(&_defunct_spinlock);
162
163#if defined(RT_USING_SMP) || defined(RT_USING_SMART)
164 rt_sem_init(&system_sem, "defunct", 0, RT_IPC_FLAG_FIFO);
165
166 /* create defunct thread */
167 rt_thread_init(&rt_system_thread,
168 "tsystem",
169 rt_thread_system_entry,
170 RT_NULL,
171 rt_system_stack,
172 sizeof(rt_system_stack),
173 RT_THREAD_PRIORITY_MAX - 2,
174 32);
175 /* startup */
176 rt_thread_startup(&rt_system_thread);
177#endif
178}
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
rt_err_t rt_thread_startup(rt_thread_t thread)
This function will start a thread and put it to system ready queue.
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.
rt_err_t rt_sem_init(rt_sem_t sem, const char *name, rt_uint32_t value, rt_uint8_t flag)
This function will initialize a static semaphore object.
定义 ipc.c:376

引用了 RT_ASSERT, RT_IPC_FLAG_FIFO, RT_NULL, rt_sem_init(), rt_spin_lock_init(), rt_thread_init() , 以及 rt_thread_startup().

+ 函数调用图:

◆ rt_thread_defunct_enqueue()

void rt_thread_defunct_enqueue ( rt_thread_t thread)

Enqueue a thread to defunct queue.

参数
threadthe thread to be enqueued.
注解
It must be called between rt_hw_interrupt_disable and rt_hw_interrupt_enable

在文件 defunct.c33 行定义.

34{
35 rt_base_t level;
36 level = rt_spin_lock_irqsave(&_defunct_spinlock);
37 rt_list_insert_after(&_rt_thread_defunct, &RT_THREAD_LIST_NODE(thread));
38 rt_spin_unlock_irqrestore(&_defunct_spinlock, level);
39#if defined(RT_USING_SMP) || defined(RT_USING_SMART)
40 rt_sem_release(&system_sem);
41#endif
42}
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
insert a node after a list
rt_err_t rt_sem_release(rt_sem_t sem)
This function will release a semaphore. If there is thread suspended on the semaphore,...
定义 ipc.c:695

引用了 rt_list_insert_after(), rt_sem_release(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 RT_THREAD_LIST_NODE.

+ 函数调用图:

◆ rt_thread_defunct_dequeue()

rt_thread_t rt_thread_defunct_dequeue ( void )

Dequeue a thread from defunct queue.

在文件 defunct.c47 行定义.

48{
49 rt_base_t level;
50 rt_thread_t thread = RT_NULL;
51 rt_list_t *l = &_rt_thread_defunct;
52
53 level = rt_spin_lock_irqsave(&_defunct_spinlock);
54 if (!rt_list_isempty(l))
55 {
58 }
59 rt_spin_unlock_irqrestore(&_defunct_spinlock, level);
60
61 return thread;
62}

引用了 rt_list_node::next, rt_list_isempty(), rt_list_remove(), RT_NULL, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore(), RT_THREAD_LIST_NODE , 以及 RT_THREAD_LIST_NODE_ENTRY.

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

◆ rt_defunct_execute()

void rt_defunct_execute ( void )

This function will perform system background job when system idle.

在文件 defunct.c67 行定义.

68{
69 /* Loop until there is no dead thread. So one call to rt_defunct_execute
70 * will do all the cleanups. */
71 while (1)
72 {
73 rt_thread_t thread;
74 rt_bool_t object_is_systemobject;
75 void (*cleanup)(struct rt_thread *tid);
76
77#ifdef RT_USING_MODULE
78 struct rt_dlmodule *module = RT_NULL;
79#endif
80 /* get defunct thread */
82 if (thread == RT_NULL)
83 {
84 break;
85 }
86
87#ifdef RT_USING_MODULE
88 module = (struct rt_dlmodule *)thread->parent.module_id;
89 if (module)
90 {
91 dlmodule_destroy(module);
92 }
93#endif
94
95#ifdef RT_USING_SIGNALS
96 rt_thread_free_sig(thread);
97#endif
98
99 /* store the point of "thread->cleanup" avoid to lose */
100 cleanup = thread->cleanup;
101
102 /* if it's a system object, detach it */
103 object_is_systemobject = rt_object_is_systemobject((rt_object_t)thread);
104 if (object_is_systemobject == RT_TRUE)
105 {
106 /* detach this object */
108 }
109
110 /* invoke thread cleanup */
111 if (cleanup != RT_NULL)
112 {
113 cleanup(thread);
114 }
115
116#ifdef RT_USING_HEAP
117#ifdef RT_USING_MEM_PROTECTION
118 if (thread->mem_regions != RT_NULL)
119 {
120 RT_KERNEL_FREE(thread->mem_regions);
121 }
122#endif
123 /* if need free, delete it */
124 if (object_is_systemobject == RT_FALSE)
125 {
126 /* release thread's stack */
127#ifdef RT_USING_HW_STACK_GUARD
128 RT_KERNEL_FREE(thread->stack_buf);
129#else
130 RT_KERNEL_FREE(thread->stack_addr);
131#endif
132 /* delete thread object */
134 }
135#endif
136 }
137}
rt_thread_t rt_thread_defunct_dequeue(void)
Dequeue a thread from defunct queue.
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.
rt_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.
void rt_object_detach(rt_object_t object)
This function will detach a static object from object system, and the memory of static object is not ...
#define RT_KERNEL_FREE(ptr)
int rt_bool_t
#define RT_TRUE
#define RT_FALSE
void * stack_addr
rt_thread_cleanup_t cleanup

引用了 rt_thread::cleanup, RT_FALSE, RT_KERNEL_FREE, RT_NULL, rt_object_delete(), rt_object_detach(), rt_object_is_systemobject(), rt_thread_defunct_dequeue(), RT_TRUE , 以及 rt_thread::stack_addr.

+ 函数调用图:

◆ rt_spin_lock_init()

void rt_spin_lock_init ( struct rt_spinlock * lock)

Initialize a static spinlock object.

参数
lockis a pointer to the spinlock to initialize.

在文件 cpu_mp.c37 行定义.

38{
39 rt_hw_spin_lock_init(&lock->lock);
40}
rt_ubase_t lock

引用了 rt_spinlock::lock , 以及 RT_UNUSED.

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

◆ rt_spin_lock()

void rt_spin_lock ( struct rt_spinlock * lock)

This function will lock the spinlock, will lock the thread scheduler.

注解
If the spinlock is locked, the current CPU will keep polling the spinlock state until the spinlock is unlocked.
参数
lockis a pointer to the spinlock.

在文件 cpu_mp.c51 行定义.

52{
54 rt_hw_spin_lock(&lock->lock);
56}
rt_base_t rt_enter_critical(void)
This function will lock the thread scheduler.
#define rt_hw_spin_lock(lock)
定义 rthw.h:235
#define RT_SPIN_LOCK_DEBUG(lock)

引用了 rt_enter_critical(), rt_hw_spin_lock, rt_spin_lock() , 以及 RT_SPIN_LOCK_DEBUG.

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

◆ rt_spin_unlock()

void rt_spin_unlock ( struct rt_spinlock * lock)

This function will unlock the spinlock, will unlock the thread scheduler.

参数
lockis a pointer to the spinlock.

在文件 cpu_mp.c64 行定义.

65{
66 rt_base_t critical_level;
67 RT_SPIN_UNLOCK_DEBUG(lock, critical_level);
68 rt_hw_spin_unlock(&lock->lock);
69 rt_exit_critical_safe(critical_level);
70}
void rt_exit_critical_safe(rt_base_t critical_level)
#define rt_hw_spin_unlock(lock)
定义 rthw.h:236
#define RT_SPIN_UNLOCK_DEBUG(lock, critical)

引用了 rt_exit_critical_safe(), rt_hw_spin_unlock, rt_spin_unlock() , 以及 RT_SPIN_UNLOCK_DEBUG.

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

◆ rt_spin_lock_irqsave()

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 scheduler.

注解
If the spinlock is locked, the current CPU will keep polling the spinlock state until the spinlock is unlocked.
参数
lockis a pointer to the spinlock.
返回
Return current cpu interrupt status.

在文件 cpu_mp.c83 行定义.

84{
85 rt_base_t level;
86
89 rt_hw_spin_lock(&lock->lock);
91 return level;
92}
#define rt_hw_local_irq_disable
定义 rthw.h:152

引用了 rt_enter_critical(), rt_hw_interrupt_disable(), rt_hw_local_irq_disable, rt_hw_spin_lock, RT_SPIN_LOCK_DEBUG, rt_spin_lock_irqsave() , 以及 RT_UNUSED.

+ 函数调用图:

◆ rt_spin_unlock_irqrestore()

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, will unlock the thread scheduler.

参数
lockis a pointer to the spinlock.
levelis interrupt status returned by rt_spin_lock_irqsave().

在文件 cpu_mp.c102 行定义.

103{
104 rt_base_t critical_level;
105
106 RT_SPIN_UNLOCK_DEBUG(lock, critical_level);
107 rt_hw_spin_unlock(&lock->lock);
108 rt_exit_critical_safe(critical_level);
110}
#define rt_hw_local_irq_enable
定义 rthw.h:153

引用了 rt_exit_critical_safe(), rt_hw_interrupt_enable(), rt_hw_local_irq_enable, rt_hw_spin_unlock, RT_SPIN_UNLOCK_DEBUG , 以及 rt_spin_unlock_irqrestore().

+ 函数调用图: