RT-Thread RTOS 1.2.0
An open source embedded real-time operating system
|
专题 | |
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) |
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.
#define RT_IPC_FLAG_FIFO 0x00 |
IPC flags and control command definitions FIFOed IPC. Inter-Thread Communication.
#define RT_IPC_FLAG_PRIO 0x01 |
PRIOed IPC. Inter-Thread Communication.
#define RT_THREAD_RESUME_RES_THR_ERR (-1) |
在文件 rtthread.h 第 401 行定义.
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.
ipc | is a pointer to the IPC object. |
引用了 rt_list_init() , 以及 rt_ipc_object::suspend_thread.
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_list | the list thread dequeued from. RT_NULL if no list. |
thread_error | thread error number of the resuming thread. A negative value in this set will be discarded, and thread error will not be changed. |
引用了 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.
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.
susp_list | is a pointer to a suspended thread list of the IPC object. |
thread_error | thread error number of the resuming thread. A negative value in this set will be discarded, and thread error will not be changed. |
引用了 RT_SCHED_DEBUG_IS_UNLOCKED , 以及 rt_susp_list_dequeue().
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.
susp_list | is a pointer to a suspended thread list of the IPC object. |
thread_error | thread error number of the resuming thread. A negative value in this set will be discarded, and thread error will not be changed. |
lock | the lock to be held while operating susp_list |
引用了 RT_SCHED_DEBUG_IS_UNLOCKED, rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 rt_susp_list_dequeue().
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
susp_list | the list thread enqueued to |
thread | the suspended thread |
ipc_flags | the pattern of suspend list |
引用了 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.
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
引用了 rt_object::name, rt_list_node::next, rt_thread::parent, rt_kprintf, rt_sched_lock(), rt_sched_unlock() , 以及 RT_THREAD_LIST_NODE_ENTRY.
rt_inline rt_uint8_t _mutex_update_priority | ( | struct rt_mutex * | mutex | ) |
引用了 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.
rt_inline rt_uint8_t _thread_get_mutex_priority | ( | struct rt_thread * | thread | ) |
引用了 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.
rt_inline void _thread_update_priority | ( | struct rt_thread * | thread, |
rt_uint8_t | priority, | ||
int | suspend_flag ) |
引用了 _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_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.
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.
thread | the thread to be suspended. |
susp_list | the list thread enqueued to. RT_NULL if no list. |
ipc_flags | is 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_flag | status flag of the thread to be suspended. |
enqueue thread on the push list before leaving critical region of scheduler, so we won't miss notification of async events.
引用了 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().
void rt_thread_defunct_init | ( | void | ) |
引用了 RT_ASSERT, RT_IPC_FLAG_FIFO, RT_NULL, rt_sem_init(), rt_spin_lock_init(), rt_thread_init() , 以及 rt_thread_startup().
void rt_thread_defunct_enqueue | ( | rt_thread_t | thread | ) |
Enqueue a thread to defunct queue.
thread | the thread to be enqueued. |
引用了 rt_list_insert_after(), rt_sem_release(), rt_spin_lock_irqsave(), rt_spin_unlock_irqrestore() , 以及 RT_THREAD_LIST_NODE.
rt_thread_t rt_thread_defunct_dequeue | ( | void | ) |
Dequeue a thread from defunct queue.
引用了 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.
void rt_defunct_execute | ( | void | ) |
This function will perform system background job when system idle.
引用了 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.
void rt_spin_lock_init | ( | struct rt_spinlock * | lock | ) |
Initialize a static spinlock object.
lock | is a pointer to the spinlock to initialize. |
引用了 rt_spinlock::lock , 以及 RT_UNUSED.
void rt_spin_lock | ( | struct rt_spinlock * | lock | ) |
This function will lock the spinlock, will lock the thread scheduler.
lock | is a pointer to the spinlock. |
引用了 rt_enter_critical(), rt_hw_spin_lock, rt_spin_lock() , 以及 RT_SPIN_LOCK_DEBUG.
void rt_spin_unlock | ( | struct rt_spinlock * | lock | ) |
This function will unlock the spinlock, will unlock the thread scheduler.
lock | is a pointer to the spinlock. |
引用了 rt_exit_critical_safe(), rt_hw_spin_unlock, rt_spin_unlock() , 以及 RT_SPIN_UNLOCK_DEBUG.
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.
lock | is a pointer to the spinlock. |
引用了 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.
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.
lock | is a pointer to the spinlock. |
level | is interrupt status returned by rt_spin_lock_irqsave(). |
引用了 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().