Browse Source

调整thread suspend状态,分成interruptible killable uninterruptible三个情况

shaojinchun 4 years ago
parent
commit
5318d57587

+ 1 - 1
bsp/gkipc/armv6/rtos_lib.c

@@ -720,7 +720,7 @@ void thread_statistics()
         rt_kprintf("%-32.*s %3d", RT_NAME_MAX, thread->name, priority);
 #endif
         if (thread->stat == RT_THREAD_READY)        rt_kprintf("   ready");
-        else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
+        else if ((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) rt_kprintf(" suspend");
         else if (thread->stat == RT_THREAD_INIT)    rt_kprintf("    init");
         else if (thread->stat == RT_THREAD_CLOSE)   rt_kprintf("   close");
 

+ 1 - 1
bsp/gkipc/armv6/trap.c

@@ -88,7 +88,7 @@ static void _rtt_statistics()
         rt_kprintf("%-32.*s %03d", RT_NAME_MAX, thread->name, priority);
 #endif
         if (thread->stat == RT_THREAD_READY)        rt_kprintf(" ready  ");
-        else if (thread->stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
+        else if ((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) rt_kprintf(" suspend");
         else if (thread->stat == RT_THREAD_INIT)    rt_kprintf(" init   ");
         else if (thread->stat == RT_THREAD_CLOSE)   rt_kprintf(" close  ");
 

+ 1 - 1
components/finsh/cmd.c

@@ -221,7 +221,7 @@ long list_thread(void)
 #endif /*RT_USING_SMP*/
                     stat = (thread->stat & RT_THREAD_STAT_MASK);
                     if (stat == RT_THREAD_READY)        rt_kprintf(" ready  ");
-                    else if (stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
+                    else if ((stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) rt_kprintf(" suspend");
                     else if (stat == RT_THREAD_INIT)    rt_kprintf(" init   ");
                     else if (stat == RT_THREAD_CLOSE)   rt_kprintf(" close  ");
                     else if (stat == RT_THREAD_RUNNING) rt_kprintf(" running");

+ 3 - 3
components/lwp/lwp_pid.c

@@ -464,7 +464,7 @@ static void print_thread_info(struct rt_thread* thread, int maxlen)
 
     stat = (thread->stat & RT_THREAD_STAT_MASK);
     if (stat == RT_THREAD_READY)        rt_kprintf(" ready  ");
-    else if (stat == RT_THREAD_SUSPEND) rt_kprintf(" suspend");
+    else if ((stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK) rt_kprintf(" suspend");
     else if (stat == RT_THREAD_INIT)    rt_kprintf(" init   ");
     else if (stat == RT_THREAD_CLOSE)   rt_kprintf(" close  ");
     else if (stat == RT_THREAD_RUNNING) rt_kprintf(" running");
@@ -694,7 +694,7 @@ void lwp_request_thread_exit(rt_thread_t thread_to_exit)
         {
             thread->exit_request = LWP_EXIT_REQUEST_TRIGGERED;
         }
-        if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+        if ((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
         {
             thread->error = RT_EINTR;
             dsb();
@@ -734,7 +734,7 @@ void lwp_terminate(struct rt_lwp *lwp)
         {
             thread->exit_request = LWP_EXIT_REQUEST_TRIGGERED;
         }
-        if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+        if ((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
         {
             thread->error = RT_EINTR;
             dsb();

+ 2 - 2
components/lwp/lwp_signal.c

@@ -255,7 +255,7 @@ int lwp_kill(pid_t pid, int sig)
     signal = (1 << sig);
     signal &= ~lwp->signal_mask;
     lwp->signal |= signal;
-    if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+    if ((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
     {
         rt_thread_wakeup(thread);
 
@@ -285,7 +285,7 @@ int lwp_thread_kill(rt_thread_t thread, int sig)
     signal = (1 << sig);
     signal &= ~thread->signal_mask;
     thread->signal |= signal;
-    if ((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+    if ((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
     {
         rt_thread_wakeup(thread);
 

+ 14 - 7
include/rtdef.h

@@ -511,13 +511,20 @@ typedef siginfo_t rt_siginfo_t;
 /*
  * thread state definitions
  */
-#define RT_THREAD_INIT                  0x00                /**< Initialized status */
-#define RT_THREAD_READY                 0x01                /**< Ready status */
-#define RT_THREAD_SUSPEND               0x02                /**< Suspend status */
-#define RT_THREAD_RUNNING               0x03                /**< Running status */
-#define RT_THREAD_BLOCK                 RT_THREAD_SUSPEND   /**< Blocked status */
-#define RT_THREAD_CLOSE                 0x04                /**< Closed status */
-#define RT_THREAD_STAT_MASK             0x07
+#define RT_THREAD_INIT                       0x00                /**< Initialized status */
+#define RT_THREAD_CLOSE                      0x01                /**< Closed status */
+#define RT_THREAD_READY                      0x02                /**< Ready status */
+#define RT_THREAD_RUNNING                    0x03                /**< Running status */
+
+#define RT_THREAD_SUSPEND_MASK               0x04
+#define RT_SIGNAL_COMMON_WAKEUP_MASK         0x02
+#define RT_SIGNAL_KILL_WAKEUP_MASK           0x01
+
+#define RT_THREAD_SUSPEND_INTERRUPTIBLE      (RT_THREAD_SUSPEND_MASK)                                                             /**< Suspend interruptable 0x4 */
+#define RT_THREAD_SUSPEND                    RT_THREAD_SUSPEND_INTERRUPTIBLE
+#define RT_THREAD_SUSPEND_KILLABLE           (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK)                              /**< Suspend with killable 0x6 */
+#define RT_THREAD_SUSPEND_UNINTERRUPTIBLE    (RT_THREAD_SUSPEND_MASK | RT_SIGNAL_COMMON_WAKEUP_MASK | RT_SIGNAL_KILL_WAKEUP_MASK) /**< Suspend with uninterruptable 0x7 */
+#define RT_THREAD_STAT_MASK                  0x07
 
 #define RT_THREAD_STAT_YIELD            0x08                /**< indicate whether remaining_tick has been reloaded since last schedule */
 #define RT_THREAD_STAT_YIELD_MASK       RT_THREAD_STAT_YIELD

+ 2 - 2
src/scheduler.c

@@ -315,7 +315,7 @@ void rt_schedule(void)
     }
 
 #ifdef RT_USING_SIGNALS
-    if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+    if ((current_thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
     {
         /* if current_thread signal is in pending */
 
@@ -559,7 +559,7 @@ void rt_scheduler_do_irq_switch(void *context)
     current_thread = pcpu->current_thread;
 
 #ifdef RT_USING_SIGNALS
-    if ((current_thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+    if ((current_thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
     {
         /* if current_thread signal is in pending */
 

+ 1 - 1
src/signal.c

@@ -102,7 +102,7 @@ static void _signal_deliver(rt_thread_t tid)
         return;
     }
 
-    if ((tid->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND)
+    if ((tid->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK)
     {
         /* resume thread to handle signal */
 #ifdef RT_USING_LWP

+ 2 - 2
src/thread.c

@@ -807,7 +807,7 @@ rt_err_t rt_thread_resume(rt_thread_t thread)
 
     RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread resume:  %s\n", thread->name));
 
-    if ((thread->stat & RT_THREAD_STAT_MASK) != RT_THREAD_SUSPEND)
+    if ((thread->stat & RT_THREAD_SUSPEND_MASK) != RT_THREAD_SUSPEND_MASK)
     {
         RT_DEBUG_LOG(RT_DEBUG_THREAD, ("thread resume: thread disorder, %d\n",
                                        thread->stat));
@@ -899,7 +899,7 @@ void rt_thread_timeout(void *parameter)
 
     /* thread check */
     RT_ASSERT(thread != RT_NULL);
-    RT_ASSERT((thread->stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND);
+    RT_ASSERT((thread->stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK);
     RT_ASSERT(rt_object_get_type((rt_object_t)thread) == RT_Object_Class_Thread);
 
     /* set error number */

+ 1 - 1
src/timer.c

@@ -415,7 +415,7 @@ rt_err_t rt_timer_start(rt_timer_t timer)
     {
         /* check whether timer thread is ready */
         if ((soft_timer_status == RT_SOFT_TIMER_IDLE) &&
-           ((timer_thread.stat & RT_THREAD_STAT_MASK) == RT_THREAD_SUSPEND))
+           ((timer_thread.stat & RT_THREAD_SUSPEND_MASK) == RT_THREAD_SUSPEND_MASK))
         {
             /* resume timer thread to check soft timer */
             rt_thread_resume(&timer_thread);