@@ -942,31 +942,40 @@ rt_err_t rt_thread_suspend_to_list(rt_thread_t thread, rt_list_t *susp_list, int
942942 /* parameter check */
943943 RT_ASSERT (thread != RT_NULL );
944944 RT_ASSERT (rt_object_get_type ((rt_object_t )thread ) == RT_Object_Class_Thread );
945-
945+
946946 LOG_D ("thread suspend: %s" , thread -> parent .name );
947+ RT_ASSERT (thread == rt_thread_self ());
947948
948949 rt_sched_lock (& slvl );
949950
950951 stat = rt_sched_thread_get_stat (thread );
951- if (stat == RT_THREAD_SUSPEND )
952+ if (stat & RT_THREAD_SUSPEND_MASK )
952953 {
953- rt_sched_unlock (slvl );
954- /* Already suspended, just set status to success. */
955- return RT_EOK ;
954+ /* Already manually suspended, just set the status to success. */
955+ if (RT_SCHED_CTX (thread ).sched_flag_ttmr_set == 0 )
956+ {
957+ /* Update if a pending flag needs */
958+ if ((stat & RT_THREAD_STAT_MASK ) < suspend_flag )
959+ {
960+ _thread_set_suspend_state (thread , suspend_flag );
961+ }
962+
963+ rt_sched_unlock (slvl );
964+ return RT_EOK ;
965+ }
966+ /* Manual suspension overrides delayed suspension. */
967+ else
968+ {
969+ LOG_D ("thread suspend: converting delay suspend to manual suspend" );
970+ }
956971 }
957972 else if ((stat != RT_THREAD_READY ) && (stat != RT_THREAD_RUNNING ))
958973 {
959- LOG_D ("thread suspend: thread disorder, 0x%2x " , RT_SCHED_CTX (thread ).stat );
974+ LOG_W ("thread suspend: thread disorder, 0x%02x " , RT_SCHED_CTX (thread ).stat );
960975 rt_sched_unlock (slvl );
961976 return - RT_ERROR ;
962977 }
963978
964- if (stat == RT_THREAD_RUNNING )
965- {
966- /* not suspend running status thread on other core */
967- RT_ASSERT (thread == rt_thread_self ());
968- }
969-
970979#ifdef RT_USING_SMART
971980 if (thread -> lwp )
972981 {
0 commit comments