Module: xenomai-forge
Branch: master
Commit: af83f60646f68dbb8197ee4d2c95a90b558b4e90
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=af83f60646f68dbb8197ee4d2c95a90b558b4e90

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Oct  2 11:09:34 2013 +0200

cobalt/rtdm: introduce rtdm_task_should_stop()

As a consequence of rebasing Xenomai kernel threads over linux
kthreads, the Cobalt core may not guarantee synchronous deletion of
kernel threads anymore.

We introduce rtdm_task_should_stop(), as a mean for RTDM driver tasks
to poll for a pending termination request, which might have been sent
to them by a call to rtdm_task_destroy(). If a true value is returned,
the caller should wrap up and exit gracefully.

In addition, to match the expectations of the existing RTDM user base
with respect to the rtdm_task_destroy() semantics, the latter now
explicitly waits for the deleted thread to terminate, before returning
to the caller.

---

 include/rtdm/rtdm_driver.h  |    6 ++++++
 kernel/cobalt/rtdm/drvlib.c |   26 ++++++++++++++++++++++++--
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
index cb80797..3c8c270 100644
--- a/include/rtdm/rtdm_driver.h
+++ b/include/rtdm/rtdm_driver.h
@@ -1094,6 +1094,12 @@ void rtdm_task_busy_sleep(nanosecs_rel_t delay);
 static inline void rtdm_task_destroy(rtdm_task_t *task)
 {
        xnthread_cancel(task);
+       xnthread_join(task);
+}
+
+static inline int rtdm_task_should_stop(void)
+{
+       return xnthread_test_info(xnshadow_current(), XNCANCELD);
 }
 
 void rtdm_task_join_nrt(rtdm_task_t *task, unsigned int poll_delay);
diff --git a/kernel/cobalt/rtdm/drvlib.c b/kernel/cobalt/rtdm/drvlib.c
index c866377..30ea6a3 100644
--- a/kernel/cobalt/rtdm/drvlib.c
+++ b/kernel/cobalt/rtdm/drvlib.c
@@ -184,6 +184,13 @@ EXPORT_SYMBOL_GPL(rtdm_task_init);
 /**
  * @brief Destroy a real-time task
  *
+ * This call sends a termination request to @a task, then waits for it
+ * to exit. All RTDM task should check for pending termination
+ * requests by calling rtdm_task_should_stop() from their work loop.
+ *
+ * If @a task is current, rtdm_task_destroy() terminates the current
+ * context, and does not return to the caller.
+ *
  * @param[in,out] task Task handle as returned by rtdm_task_init()
  *
  * @note Passing the same task handle to RTDM services after the completion of
@@ -195,13 +202,28 @@ EXPORT_SYMBOL_GPL(rtdm_task_init);
  *
  * - Kernel module initialization/cleanup code
  * - Kernel-based task
- * - User-space task (RT, non-RT)
  *
- * Rescheduling: never.
+ * Rescheduling: yes.
  */
 void rtdm_task_destroy(rtdm_task_t *task);
 
 /**
+ * @brief Check for pending termination request
+ *
+ * Check whether a termination request was received by the current
+ * RTDM task. Termination requests are sent by calling
+ * rtdm_task_destroy().
+ *
+ * @return Non-zero indicates that a termination request is pending,
+ * in which case the caller should wrap up and exit.
+ *
+ * Calling context: kernel task
+ *
+ * Rescheduling: none.
+ */
+int rtdm_task_should_stop(void);
+
+/**
  * @brief Adjust real-time task priority
  *
  * @param[in,out] task Task handle as returned by rtdm_task_init()


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to