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

结构体

struct  rt_mutex
 

类型定义

typedef struct rt_mutexrt_mutex_t
 

函数

rt_err_t rt_mutex_init (rt_mutex_t mutex, const char *name, rt_uint8_t flag)
 
 RTM_EXPORT (rt_mutex_init)
 
rt_err_t rt_mutex_detach (rt_mutex_t mutex)
 
 RTM_EXPORT (rt_mutex_detach)
 
void rt_mutex_drop_thread (rt_mutex_t mutex, rt_thread_t thread)
 
rt_uint8_t rt_mutex_setprioceiling (rt_mutex_t mutex, rt_uint8_t priority)
 
 RTM_EXPORT (rt_mutex_setprioceiling)
 
rt_uint8_t rt_mutex_getprioceiling (rt_mutex_t mutex)
 
 RTM_EXPORT (rt_mutex_getprioceiling)
 
rt_mutex_t rt_mutex_create (const char *name, rt_uint8_t flag)
 
 RTM_EXPORT (rt_mutex_create)
 
rt_err_t rt_mutex_delete (rt_mutex_t mutex)
 
 RTM_EXPORT (rt_mutex_delete)
 
rt_err_t rt_mutex_take (rt_mutex_t mutex, rt_int32_t time)
 
 RTM_EXPORT (rt_mutex_take)
 
rt_err_t rt_mutex_take_interruptible (rt_mutex_t mutex, rt_int32_t time)
 
 RTM_EXPORT (rt_mutex_take_interruptible)
 
rt_err_t rt_mutex_take_killable (rt_mutex_t mutex, rt_int32_t time)
 
 RTM_EXPORT (rt_mutex_take_killable)
 
rt_err_t rt_mutex_trytake (rt_mutex_t mutex)
 
 RTM_EXPORT (rt_mutex_trytake)
 
rt_err_t rt_mutex_release (rt_mutex_t mutex)
 
 RTM_EXPORT (rt_mutex_release)
 
rt_err_t rt_mutex_control (rt_mutex_t mutex, int cmd, void *arg)
 
 RTM_EXPORT (rt_mutex_control)
 
rt_inline rt_thread_t rt_mutex_get_owner (rt_mutex_t mutex)
 
rt_inline rt_ubase_t rt_mutex_get_hold (rt_mutex_t mutex)
 

详细描述

类型定义说明

◆ rt_mutex_t

typedef struct rt_mutex* rt_mutex_t

在文件 rtdef.h1037 行定义.

函数说明

◆ rt_mutex_init()

rt_err_t rt_mutex_init ( rt_mutex_t mutex,
const char * name,
rt_uint8_t flag )

Initialize a static mutex object.

注解
For the static mutex object, its memory space is allocated by the compiler during compiling, and shall placed on the read-write data segment or on the uninitialized data segment. By contrast, the rt_mutex_create() function will automatically allocate memory space and initialize the mutex.
参见
rt_mutex_create()
参数
mutexis a pointer to the mutex to initialize. It is assumed that storage for the mutex will be allocated in your application.
nameis a pointer to the name that given to the mutex.
flagis the mutex flag, which determines the queuing way of how multiple threads wait when the mutex is not available. NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. If the return value is any other values, it represents the initialization failed.
警告
This function can ONLY be called from threads.

在文件 ipc.c1007 行定义.

1008{
1009 /* flag parameter has been obsoleted */
1010 RT_UNUSED(flag);
1011
1012 /* parameter check */
1013 RT_ASSERT(mutex != RT_NULL);
1014
1015 /* initialize object */
1017
1018 /* initialize ipc object */
1019 _ipc_object_init(&(mutex->parent));
1020
1021 mutex->owner = RT_NULL;
1022 mutex->priority = 0xFF;
1023 mutex->hold = 0;
1024 mutex->ceiling_priority = 0xFF;
1025 rt_list_init(&(mutex->taken_list));
1026
1027 /* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */
1029 rt_spin_lock_init(&(mutex->spinlock));
1030
1031 return RT_EOK;
1032}
#define RT_IPC_FLAG_PRIO
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.c:82
void rt_spin_lock_init(struct rt_spinlock *lock)
Initialize a static spinlock object.
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.
@ RT_Object_Class_Mutex
#define RT_ASSERT(EX)
rt_inline void rt_list_init(rt_list_t *l)
initialize a list
#define RT_UNUSED(x)
#define RT_NULL
struct rt_object parent
struct rt_spinlock spinlock
rt_uint8_t ceiling_priority
struct rt_ipc_object parent
rt_list_t taken_list
rt_uint8_t priority
struct rt_thread * owner
rt_uint8_t hold
rt_uint8_t flag

引用了 _ipc_object_init(), rt_mutex::ceiling_priority, rt_object::flag, rt_mutex::hold, rt_mutex::owner, rt_ipc_object::parent, rt_mutex::parent, rt_mutex::priority, RT_ASSERT, RT_IPC_FLAG_PRIO, rt_list_init(), RT_NULL, RT_Object_Class_Mutex, rt_object_init(), rt_spin_lock_init(), RT_UNUSED, rt_mutex::spinlock , 以及 rt_mutex::taken_list.

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

◆ RTM_EXPORT() [1/12]

RTM_EXPORT ( rt_mutex_init )

引用了 rt_mutex_init().

+ 函数调用图:

◆ rt_mutex_detach()

rt_err_t rt_mutex_detach ( rt_mutex_t mutex)

This function will detach a static mutex object.

注解
This function is used to detach a static mutex object which is initialized by rt_mutex_init() function. By contrast, the rt_mutex_delete() function will delete a mutex object. When the mutex is successfully detached, it will resume all suspended threads in the mutex list.
参见
rt_mutex_delete()
参数
mutexis a pointer to a mutex object to be detached.
返回
Return the operation status. When the return value is RT_EOK, the initialization is successful. If the return value is any other values, it means that the mutex detach failed.
警告
This function can ONLY detach a static mutex initialized by the rt_mutex_init() function. If the mutex is created by the rt_mutex_create() function, you MUST NOT USE this function to detach it, ONLY USE the rt_mutex_delete() function to complete the deletion.

在文件 ipc.c1054 行定义.

1055{
1056 /* parameter check */
1057 RT_ASSERT(mutex != RT_NULL);
1060
1061 _mutex_before_delete_detach(mutex);
1062
1063 /* detach mutex object */
1064 rt_object_detach(&(mutex->parent.parent));
1065
1066 return RT_EOK;
1067}
rt_bool_t rt_object_is_systemobject(rt_object_t object)
This function will judge the object is system object or not.
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.
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 ...

引用了 rt_ipc_object::parent, rt_mutex::parent, RT_ASSERT, RT_NULL, RT_Object_Class_Mutex, rt_object_detach(), rt_object_get_type() , 以及 rt_object_is_systemobject().

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

◆ RTM_EXPORT() [2/12]

RTM_EXPORT ( rt_mutex_detach )

引用了 rt_mutex_detach().

+ 函数调用图:

◆ rt_mutex_drop_thread()

void rt_mutex_drop_thread ( rt_mutex_t mutex,
rt_thread_t thread )

drop a thread from the suspend list of mutex

参数
mutexis a pointer to a mutex object.
threadis the thread should be dropped from mutex.

Should change the priority of mutex owner thread Note: After current thread is detached from mutex pending list, there is a chance that the mutex owner has been released the mutex. Which means mutex->owner can be NULL at this point. If that happened, it had already reset its priority. So it's okay to skip

在文件 ipc.c1078 行定义.

1079{
1080 rt_uint8_t priority;
1081 rt_bool_t need_update = RT_FALSE;
1083
1084 /* parameter check */
1086 RT_ASSERT(mutex != RT_NULL);
1087 RT_ASSERT(thread != RT_NULL);
1088
1089 rt_spin_lock(&(mutex->spinlock));
1090
1091 RT_ASSERT(thread->pending_object == &mutex->parent.parent);
1092
1093 rt_sched_lock(&slvl);
1094
1095 /* detach from suspended list */
1097
1105 if (mutex->owner && rt_sched_thread_get_curr_prio(mutex->owner) ==
1107 {
1108 need_update = RT_TRUE;
1109 }
1110
1111 /* update the priority of mutex */
1113 {
1114 /* more thread suspended in the list */
1115 struct rt_thread *th;
1116
1118 /* update the priority of mutex */
1120 }
1121 else
1122 {
1123 /* set mutex priority to maximal priority */
1124 mutex->priority = 0xff;
1125 }
1126
1127 /* try to change the priority of mutex owner thread */
1128 if (need_update)
1129 {
1130 /* get the maximal priority of mutex in thread */
1131 priority = _thread_get_mutex_priority(mutex->owner);
1132 if (priority != rt_sched_thread_get_curr_prio(mutex->owner))
1133 {
1135 }
1136 }
1137
1138 rt_sched_unlock(slvl);
1139 rt_spin_unlock(&(mutex->spinlock));
1140}
rt_inline void _thread_update_priority(struct rt_thread *thread, rt_uint8_t priority, int suspend_flag)
定义 ipc.c:868
rt_inline rt_uint8_t _thread_get_mutex_priority(struct rt_thread *thread)
定义 ipc.c:845
void rt_spin_lock(struct rt_spinlock *lock)
This function will lock the spinlock, will lock the thread scheduler.
void rt_spin_unlock(struct rt_spinlock *lock)
This function will unlock the spinlock, will unlock the thread scheduler.
rt_inline void rt_list_remove(rt_list_t *n)
remove node from list.
rt_inline int rt_list_isempty(const rt_list_t *l)
tests whether a list is empty
#define RT_DEBUG_IN_THREAD_CONTEXT
@ RT_UNINTERRUPTIBLE
#define RT_THREAD_LIST_NODE(thread)
#define RT_THREAD_LIST_NODE_ENTRY(node)
rt_ubase_t rt_sched_lock_level_t
int rt_bool_t
unsigned char rt_uint8_t
#define RT_TRUE
#define RT_FALSE
rt_uint8_t rt_sched_thread_get_curr_prio(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_list_t suspend_thread
struct rt_list_node * next
rt_object_t pending_object

引用了 _thread_get_mutex_priority(), _thread_update_priority(), rt_list_node::next, rt_mutex::owner, rt_ipc_object::parent, rt_mutex::parent, rt_thread::pending_object, rt_mutex::priority, RT_ASSERT, RT_DEBUG_IN_THREAD_CONTEXT, RT_FALSE, rt_list_isempty(), rt_list_remove(), RT_NULL, rt_sched_lock(), rt_sched_thread_get_curr_prio(), rt_sched_unlock(), rt_spin_lock(), rt_spin_unlock(), RT_THREAD_LIST_NODE, RT_THREAD_LIST_NODE_ENTRY, RT_TRUE, RT_UNINTERRUPTIBLE, rt_mutex::spinlock , 以及 rt_ipc_object::suspend_thread.

+ 函数调用图:

◆ rt_mutex_setprioceiling()

rt_uint8_t rt_mutex_setprioceiling ( rt_mutex_t mutex,
rt_uint8_t priority )

set the prioceiling attribute of the mutex.

参数
mutexis a pointer to a mutex object.
priorityis the priority should be set to mutex.
返回
return the old priority ceiling

在文件 ipc.c1151 行定义.

1152{
1153 rt_uint8_t ret_priority = 0xFF;
1154 rt_uint8_t highest_prio;
1156
1158
1159 if ((mutex) && (priority < RT_THREAD_PRIORITY_MAX))
1160 {
1161 /* critical section here if multiple updates to one mutex happen */
1162 rt_spin_lock(&(mutex->spinlock));
1163 ret_priority = mutex->ceiling_priority;
1164 mutex->ceiling_priority = priority;
1165 if (mutex->owner)
1166 {
1167 rt_sched_lock(&slvl);
1168 highest_prio = _thread_get_mutex_priority(mutex->owner);
1169 if (highest_prio != rt_sched_thread_get_curr_prio(mutex->owner))
1170 {
1171 _thread_update_priority(mutex->owner, highest_prio, RT_UNINTERRUPTIBLE);
1172 }
1173 rt_sched_unlock(slvl);
1174 }
1175 rt_spin_unlock(&(mutex->spinlock));
1176 }
1177 else
1178 {
1179 rt_set_errno(-RT_EINVAL);
1180 }
1181
1182 return ret_priority;
1183}

引用了 _thread_get_mutex_priority(), _thread_update_priority(), rt_mutex::ceiling_priority, rt_mutex::owner, RT_DEBUG_IN_THREAD_CONTEXT, rt_sched_lock(), rt_sched_thread_get_curr_prio(), rt_sched_unlock(), rt_spin_lock(), rt_spin_unlock(), RT_UNINTERRUPTIBLE , 以及 rt_mutex::spinlock.

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

◆ RTM_EXPORT() [3/12]

RTM_EXPORT ( rt_mutex_setprioceiling )

引用了 rt_mutex_setprioceiling().

+ 函数调用图:

◆ rt_mutex_getprioceiling()

rt_uint8_t rt_mutex_getprioceiling ( rt_mutex_t mutex)

set the prioceiling attribute of the mutex.

参数
mutexis a pointer to a mutex object.
返回
return the current priority ceiling of the mutex.

在文件 ipc.c1194 行定义.

1195{
1196 rt_uint8_t prio = 0xFF;
1197
1198 /* parameter check */
1200 RT_ASSERT(mutex != RT_NULL);
1201
1202 if (mutex)
1203 {
1204 rt_spin_lock(&(mutex->spinlock));
1205 prio = mutex->ceiling_priority;
1206 rt_spin_unlock(&(mutex->spinlock));
1207 }
1208
1209 return prio;
1210}

引用了 rt_mutex::ceiling_priority, RT_ASSERT, RT_DEBUG_IN_THREAD_CONTEXT, RT_NULL, rt_spin_lock(), rt_spin_unlock() , 以及 rt_mutex::spinlock.

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

◆ RTM_EXPORT() [4/12]

RTM_EXPORT ( rt_mutex_getprioceiling )

引用了 rt_mutex_getprioceiling().

+ 函数调用图:

◆ rt_mutex_create()

rt_mutex_t rt_mutex_create ( const char * name,
rt_uint8_t flag )

This function will create a mutex object.

注解
For the mutex object, its memory space is automatically allocated. By contrast, the rt_mutex_init() function will initialize a static mutex object.
参见
rt_mutex_init()
参数
nameis a pointer to the name that given to the mutex.
flagis the mutex flag, which determines the queuing way of how multiple threads wait when the mutex is not available. NOTE: This parameter has been obsoleted. It can be RT_IPC_FLAG_PRIO, RT_IPC_FLAG_FIFO or RT_NULL.
返回
Return a pointer to the mutex object. When the return value is RT_NULL, it means the creation failed.
警告
This function can ONLY be called from threads.

在文件 ipc.c1233 行定义.

1234{
1235 struct rt_mutex *mutex;
1236
1237 /* flag parameter has been obsoleted */
1238 RT_UNUSED(flag);
1239
1241
1242 /* allocate object */
1244 if (mutex == RT_NULL)
1245 return mutex;
1246
1247 /* initialize ipc object */
1248 _ipc_object_init(&(mutex->parent));
1249
1250 mutex->owner = RT_NULL;
1251 mutex->priority = 0xFF;
1252 mutex->hold = 0;
1253 mutex->ceiling_priority = 0xFF;
1254 rt_list_init(&(mutex->taken_list));
1255
1256 /* flag can only be RT_IPC_FLAG_PRIO. RT_IPC_FLAG_FIFO cannot solve the unbounded priority inversion problem */
1258 rt_spin_lock_init(&(mutex->spinlock));
1259
1260 return mutex;
1261}
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_DEBUG_NOT_IN_INTERRUPT
struct rt_mutex * rt_mutex_t

引用了 _ipc_object_init(), rt_mutex::ceiling_priority, rt_object::flag, rt_mutex::hold, rt_mutex::owner, rt_ipc_object::parent, rt_mutex::parent, rt_mutex::priority, RT_DEBUG_NOT_IN_INTERRUPT, RT_IPC_FLAG_PRIO, rt_list_init(), RT_NULL, rt_object_allocate(), RT_Object_Class_Mutex, rt_spin_lock_init(), RT_UNUSED, rt_mutex::spinlock , 以及 rt_mutex::taken_list.

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

◆ RTM_EXPORT() [5/12]

RTM_EXPORT ( rt_mutex_create )

引用了 rt_mutex_create().

+ 函数调用图:

◆ rt_mutex_delete()

rt_err_t rt_mutex_delete ( rt_mutex_t mutex)

This function will delete a mutex object and release this memory space.

注解
This function is used to delete a mutex object which is created by the rt_mutex_create() function. By contrast, the rt_mutex_detach() function will detach a static mutex object. When the mutex is successfully deleted, it will resume all suspended threads in the mutex list.
参见
rt_mutex_detach()
参数
mutexis a pointer to a mutex object to be deleted.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the mutex detach failed.
警告
This function can ONLY delete a mutex initialized by the rt_mutex_create() function. If the mutex is initialized by the rt_mutex_init() function, you MUST NOT USE this function to delete it, ONLY USE the rt_mutex_detach() function to complete the detachment.

在文件 ipc.c1283 行定义.

1284{
1285 /* parameter check */
1286 RT_ASSERT(mutex != RT_NULL);
1289
1291
1292 _mutex_before_delete_detach(mutex);
1293
1294 /* delete mutex object */
1295 rt_object_delete(&(mutex->parent.parent));
1296
1297 return RT_EOK;
1298}
void rt_object_delete(rt_object_t object)
This function will delete an object and release object memory.

引用了 rt_ipc_object::parent, rt_mutex::parent, RT_ASSERT, RT_DEBUG_NOT_IN_INTERRUPT, RT_FALSE, RT_NULL, RT_Object_Class_Mutex, rt_object_delete(), rt_object_get_type() , 以及 rt_object_is_systemobject().

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

◆ RTM_EXPORT() [6/12]

RTM_EXPORT ( rt_mutex_delete )

引用了 rt_mutex_delete(), RT_MUTEX_HOLD_MAX, RT_NULL, RT_Object_Class_Mutex , 以及 RT_TRUE.

+ 函数调用图:

◆ rt_mutex_take()

rt_err_t rt_mutex_take ( rt_mutex_t mutex,
rt_int32_t time )

在文件 ipc.c1537 行定义.

1538{
1539 return _rt_mutex_take(mutex, time, RT_UNINTERRUPTIBLE);
1540}

引用了 RT_UNINTERRUPTIBLE.

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

◆ RTM_EXPORT() [7/12]

RTM_EXPORT ( rt_mutex_take )

引用了 rt_mutex_take().

+ 函数调用图:

◆ rt_mutex_take_interruptible()

rt_err_t rt_mutex_take_interruptible ( rt_mutex_t mutex,
rt_int32_t time )

在文件 ipc.c1543 行定义.

1544{
1545 return _rt_mutex_take(mutex, time, RT_INTERRUPTIBLE);
1546}
@ RT_INTERRUPTIBLE

引用了 RT_INTERRUPTIBLE.

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

◆ RTM_EXPORT() [8/12]

引用了 rt_mutex_take_interruptible().

+ 函数调用图:

◆ rt_mutex_take_killable()

rt_err_t rt_mutex_take_killable ( rt_mutex_t mutex,
rt_int32_t time )

在文件 ipc.c1549 行定义.

1550{
1551 return _rt_mutex_take(mutex, time, RT_KILLABLE);
1552}
@ RT_KILLABLE

引用了 RT_KILLABLE.

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

◆ RTM_EXPORT() [9/12]

RTM_EXPORT ( rt_mutex_take_killable )

引用了 rt_mutex_take_killable().

+ 函数调用图:

◆ rt_mutex_trytake()

rt_err_t rt_mutex_trytake ( rt_mutex_t mutex)

This function will try to take a mutex, if the mutex is unavailable, the thread returns immediately.

注解
This function is very similar to the rt_mutex_take() function, when the mutex is not available, except that rt_mutex_trytake() will return immediately without waiting for a timeout when the mutex is not available. In other words, rt_mutex_trytake(mutex) has the same effect as rt_mutex_take(mutex, 0).
参见
rt_mutex_take()
参数
mutexis a pointer to a mutex object.
返回
Return the operation status. ONLY When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the mutex take failed.

在文件 ipc.c1570 行定义.

1571{
1572 return rt_mutex_take(mutex, RT_WAITING_NO);
1573}
#define RT_WAITING_NO
rt_err_t rt_mutex_take(rt_mutex_t mutex, rt_int32_t time)
定义 ipc.c:1537

引用了 rt_mutex_take() , 以及 RT_WAITING_NO.

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

◆ RTM_EXPORT() [10/12]

RTM_EXPORT ( rt_mutex_trytake )

引用了 rt_mutex_trytake().

+ 函数调用图:

◆ rt_mutex_release()

rt_err_t rt_mutex_release ( rt_mutex_t mutex)

This function will release a mutex. If there is thread suspended on the mutex, the thread will be resumed.

注解
If there are threads suspended on this mutex, the first thread in the list of this mutex object will be resumed, and a thread scheduling (rt_schedule) will be executed. If no threads are suspended on this mutex, the count value mutex->value of this mutex will increase by 1.
参数
mutexis a pointer to a mutex object.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that the mutex release failed.

a timeout timer had triggered while we try. So we skip this thread and try again.

在文件 ipc.c1589 行定义.

1590{
1592 struct rt_thread *thread;
1593 rt_bool_t need_schedule;
1594
1595 /* parameter check */
1596 RT_ASSERT(mutex != RT_NULL);
1598
1599 need_schedule = RT_FALSE;
1600
1601 /* only thread could release mutex because we need test the ownership */
1603
1604 /* get current thread */
1605 thread = rt_thread_self();
1606
1607 rt_spin_lock(&(mutex->spinlock));
1608
1609 LOG_D("mutex_release:current thread %s, hold: %d",
1610 thread->parent.name, mutex->hold);
1611
1612 RT_OBJECT_HOOK_CALL(rt_object_put_hook, (&(mutex->parent.parent)));
1613
1614 /* mutex only can be released by owner */
1615 if (thread != mutex->owner)
1616 {
1617 thread->error = -RT_ERROR;
1618 rt_spin_unlock(&(mutex->spinlock));
1619
1620 return -RT_ERROR;
1621 }
1622
1623 /* decrease hold */
1624 mutex->hold --;
1625 /* if no hold */
1626 if (mutex->hold == 0)
1627 {
1628 rt_sched_lock(&slvl);
1629
1630 /* remove mutex from thread's taken list */
1631 rt_list_remove(&mutex->taken_list);
1632
1633 /* whether change the thread priority */
1634 need_schedule = _check_and_update_prio(thread, mutex);
1635
1636 /* wakeup suspended thread */
1638 {
1639 struct rt_thread *next_thread;
1640 do
1641 {
1642 /* get the first suspended thread */
1644
1646
1647 /* remove the thread from the suspended list of mutex */
1648 rt_list_remove(&RT_THREAD_LIST_NODE(next_thread));
1649
1650 /* resume thread to ready queue */
1651 if (rt_sched_thread_ready(next_thread) != RT_EOK)
1652 {
1657 next_thread = RT_NULL;
1658 }
1659 } while (!next_thread && !rt_list_isempty(&mutex->parent.suspend_thread));
1660
1661 if (next_thread)
1662 {
1663 LOG_D("mutex_release: resume thread: %s",
1664 next_thread->parent.name);
1665
1666 /* set new owner and put mutex into taken list of thread */
1667 mutex->owner = next_thread;
1668 mutex->hold = 1;
1669 rt_list_insert_after(&next_thread->taken_object_list, &mutex->taken_list);
1670
1671 /* cleanup pending object */
1672 next_thread->pending_object = RT_NULL;
1673
1674 /* update mutex priority */
1675 if (!rt_list_isempty(&(mutex->parent.suspend_thread)))
1676 {
1677 struct rt_thread *th;
1678
1681 }
1682 else
1683 {
1684 mutex->priority = 0xff;
1685 }
1686
1687 need_schedule = RT_TRUE;
1688 }
1689 else
1690 {
1691 /* no waiting thread is woke up, clear owner */
1692 mutex->owner = RT_NULL;
1693 mutex->priority = 0xff;
1694 }
1695
1696 rt_sched_unlock(slvl);
1697 }
1698 else
1699 {
1700 rt_sched_unlock(slvl);
1701
1702 /* clear owner */
1703 mutex->owner = RT_NULL;
1704 mutex->priority = 0xff;
1705 }
1706 }
1707
1708 rt_spin_unlock(&(mutex->spinlock));
1709
1710 /* perform a schedule */
1711 if (need_schedule == RT_TRUE)
1712 rt_schedule();
1713
1714 return RT_EOK;
1715}
#define RT_OBJECT_HOOK_CALL(func, argv)
rt_inline void rt_list_insert_after(rt_list_t *l, rt_list_t *n)
insert a node after a list
rt_thread_t rt_thread_self(void)
This function will return self thread object.
void rt_schedule(void)
This function will perform one scheduling. It will select one thread with the highest priority level ...
#define LOG_D(...)
rt_err_t rt_sched_thread_ready(struct rt_thread *thread)
rt_uint8_t rt_sched_thread_is_suspended(struct rt_thread *thread)
const char * name
rt_err_t error
struct rt_object parent
rt_list_t taken_object_list

引用了 rt_thread::error, rt_mutex::hold, LOG_D, rt_object::name, rt_list_node::next, rt_mutex::owner, rt_ipc_object::parent, rt_mutex::parent, rt_thread::parent, rt_thread::pending_object, rt_mutex::priority, RT_ASSERT, RT_DEBUG_IN_THREAD_CONTEXT, RT_FALSE, rt_list_insert_after(), rt_list_isempty(), rt_list_remove(), RT_NULL, RT_Object_Class_Mutex, rt_object_get_type(), RT_OBJECT_HOOK_CALL, rt_sched_lock(), rt_sched_thread_get_curr_prio(), rt_sched_thread_is_suspended(), rt_sched_thread_ready(), rt_sched_unlock(), rt_schedule(), rt_spin_lock(), rt_spin_unlock(), RT_THREAD_LIST_NODE, RT_THREAD_LIST_NODE_ENTRY, rt_thread_self(), RT_TRUE, rt_mutex::spinlock, rt_ipc_object::suspend_thread, rt_mutex::taken_list , 以及 rt_thread::taken_object_list.

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

◆ RTM_EXPORT() [11/12]

RTM_EXPORT ( rt_mutex_release )

引用了 rt_mutex_release().

+ 函数调用图:

◆ rt_mutex_control()

rt_err_t rt_mutex_control ( rt_mutex_t mutex,
int cmd,
void * arg )

This function will set some extra attributions of a mutex object.

注解
Currently this function does not implement the control function.
参数
mutexis a pointer to a mutex object.
cmdis a command word used to configure some attributions of the mutex.
argis the argument of the function to execute the command.
返回
Return the operation status. When the return value is RT_EOK, the operation is successful. If the return value is any other values, it means that this function failed to execute.

在文件 ipc.c1733 行定义.

1734{
1735 RT_UNUSED(mutex);
1736 RT_UNUSED(cmd);
1737 RT_UNUSED(arg);
1738
1739 return -RT_EINVAL;
1740}

引用了 RT_UNUSED.

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

◆ RTM_EXPORT() [12/12]

RTM_EXPORT ( rt_mutex_control )

引用了 rt_mutex_control().

+ 函数调用图:

◆ rt_mutex_get_owner()

rt_inline rt_thread_t rt_mutex_get_owner ( rt_mutex_t mutex)

在文件 rtthread.h468 行定义.

469{
470 return mutex->owner;
471}

引用了 rt_mutex::owner.

◆ rt_mutex_get_hold()

rt_inline rt_ubase_t rt_mutex_get_hold ( rt_mutex_t mutex)

在文件 rtthread.h472 行定义.

473{
474 return mutex->hold;
475}

引用了 rt_mutex::hold.