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

Function _thread_update_priority

src/ipc.c:869–921  ·  view source on GitHub ↗

update priority of target thread and the thread suspended it if any */

Source from the content-addressed store, hash-verified

867
868/* update priority of target thread and the thread suspended it if any */
869rt_inline void _thread_update_priority(struct rt_thread *thread, rt_uint8_t priority, int suspend_flag)
870{
871 rt_err_t ret = -RT_ERROR;
872 struct rt_object* pending_obj = RT_NULL;
873
874 LOG_D("thread:%s priority -> %d", thread->parent.name, priority);
875
876 /* change priority of the thread */
877 ret = rt_sched_thread_change_priority(thread, priority);
878
879 while ((ret == RT_EOK) && rt_sched_thread_is_suspended(thread))
880 {
881 /* whether change the priority of taken mutex */
882 pending_obj = thread->pending_object;
883
884 if (pending_obj && rt_object_get_type(pending_obj) == RT_Object_Class_Mutex)
885 {
886 rt_uint8_t mutex_priority = 0xff;
887 struct rt_mutex* pending_mutex = (struct rt_mutex *)pending_obj;
888
889 /* re-insert thread to suspended thread list to resort priority list */
890 rt_list_remove(&RT_THREAD_LIST_NODE(thread));
891
892 ret = rt_susp_list_enqueue(
893 &(pending_mutex->parent.suspend_thread), thread,
894 pending_mutex->parent.parent.flag);
895 if (ret == RT_EOK)
896 {
897 /* update priority */
898 _mutex_update_priority(pending_mutex);
899 /* change the priority of mutex owner thread */
900 LOG_D("mutex: %s priority -> %d", pending_mutex->parent.parent.name,
901 pending_mutex->priority);
902
903 mutex_priority = _thread_get_mutex_priority(pending_mutex->owner);
904 if (mutex_priority != rt_sched_thread_get_curr_prio(pending_mutex->owner))
905 {
906 thread = pending_mutex->owner;
907
908 ret = rt_sched_thread_change_priority(thread, mutex_priority);
909 }
910 else
911 {
912 ret = -RT_ERROR;
913 }
914 }
915 }
916 else
917 {
918 ret = -RT_ERROR;
919 }
920 }
921}
922
923static rt_bool_t _check_and_update_prio(rt_thread_t thread, rt_mutex_t mutex)
924{

Callers 3

rt_mutex_drop_threadFunction · 0.85
rt_mutex_setprioceilingFunction · 0.85
_rt_mutex_takeFunction · 0.85

Calls 8

rt_object_get_typeFunction · 0.85
rt_list_removeFunction · 0.85
rt_susp_list_enqueueFunction · 0.85
_mutex_update_priorityFunction · 0.85

Tested by

no test coverage detected