From db6e66852440a50e607c1df4cdf309c52a861430 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Fri, 13 May 2016 14:52:38 +0900
Subject: more fixes for chopstx_poll

---
 ChangeLog |  2 ++
 chopstx.c | 13 ++++++-------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index aa452dc..f64d911 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2016-05-13  NIIBE Yutaka  <gniibe@fsij.org>
 
 	* chopstx.c (chx_sched) [__ARM_ARCH_6M__]: Fix asm.
+	(chx_handle_intr, chx_wakeup, chopstx_cancel): Fix for polling
+	with no timeout.
 
 	* example-cdc/sample.c (main): Update chopstx_poll example.
 	* example-fs-bb48/sample.c (main): Ditto.
diff --git a/chopstx.c b/chopstx.c
index 14d3f82..3171215 100644
--- a/chopstx.c
+++ b/chopstx.c
@@ -245,10 +245,6 @@ static struct chx_queue q_join;
 
 /* Forward declaration(s). */
 static void chx_request_preemption (uint16_t prio);
-static void chx_timer_dequeue (struct chx_thread *tp);
-static struct chx_thread *chx_timer_insert (struct chx_thread *tp,
-					    uint32_t usec);
-
 
 
 /**************/
@@ -641,7 +637,8 @@ chx_handle_intr (void)
 	{
 	  if (intr->tp->state == THREAD_WAIT_POLL)
 	    {
-	      chx_timer_dequeue (intr->tp);
+	      if (intr->tp->parent == &q_timer.q)
+		chx_timer_dequeue (intr->tp);
 	      chx_ready_enqueue (intr->tp);
 	      chx_request_preemption (intr->tp->prio);
 	    }
@@ -938,7 +935,8 @@ chx_wakeup (struct chx_thread *tp)
       tp = px->master;
       if (tp->state == THREAD_WAIT_POLL)
 	{
-	  chx_timer_dequeue (tp);
+	  if (tp->parent == &q_timer.q)
+	    chx_timer_dequeue (tp);
 	  ((struct chx_stack_regs *)tp->tc.reg[REG_SP])->reg[REG_R0] = -1;
 	  chx_ready_enqueue (tp);
 	  if (tp->prio > running->prio)
@@ -1761,7 +1759,8 @@ chopstx_cancel (chopstx_t thd)
 	  ll_dequeue ((struct chx_pq *)tp);
 	  chx_spin_unlock (&cond->lock);
 	}
-      else if (tp->state == THREAD_WAIT_TIME || tp->state == THREAD_WAIT_POLL)
+      else if ((tp->state == THREAD_WAIT_TIME || tp->state == THREAD_WAIT_POLL)
+	       && (tp->parent == &q_timer.q))
 	chx_timer_dequeue (tp);
 
       chx_ready_enqueue (tp);
-- 
cgit v1.2.3