From bc664fe94357301499294678de9b415ca05e2ef5 Mon Sep 17 00:00:00 2001
From: NIIBE Yutaka <gniibe@fsij.org>
Date: Wed, 12 Oct 2016 12:06:37 +0900
Subject: chopstx_join is cancellation point.

---
 ChangeLog |  5 +++++
 chopstx.c | 10 +++++++++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 169634b..c430ea8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-10-12  NIIBE Yutaka  <gniibe@fsij.org>
+
+	* chopstx.c (chopstx_join, chopstx_cancel): chopstx_join is
+	cancellation point.
+
 2016-07-11  NIIBE Yutaka  <gniibe@fsij.org>
 
 	* mcu/stm32f103.h: Add more from Gnuk 1.1.9.
diff --git a/chopstx.c b/chopstx.c
index 6d9de04..2f7189f 100644
--- a/chopstx.c
+++ b/chopstx.c
@@ -1559,6 +1559,8 @@ chopstx_join (chopstx_t thd, void **ret)
    * We don't offer deadlock detection.  It's users' responsibility.
    */
 
+  chopstx_testcancel ();
+
   chx_cpu_sched_lock ();
   if (tp->flag_detached)
     {
@@ -1661,7 +1663,7 @@ chopstx_cancel (chopstx_t thd)
       return;
     }
 
-  /* Cancellation points: cond_wait, usec_wait, and poll.  */
+  /* Cancellation points: cond_wait, usec_wait, join, and poll.  */
   if (tp->state == THREAD_WAIT_CND)
     {
       struct chx_cond *cond = (struct chx_cond *)tp->parent;
@@ -1672,6 +1674,12 @@ chopstx_cancel (chopstx_t thd)
     }
   else if (tp->state == THREAD_WAIT_TIME)
     chx_timer_dequeue (tp);
+  else if (tp->state == THREAD_WAIT_EXIT)
+    {
+      chx_spin_lock (&q_join.lock);
+      ll_dequeue ((struct chx_pq *)tp);
+      chx_spin_unlock (&q_join.lock);
+    }
   else if (tp->state == THREAD_WAIT_POLL)
     {
       if (tp->parent == &q_timer.q)
-- 
cgit v1.2.3