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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Sep 30 17:45:43 2013 +0200

lib/cobalt: always enable async cancellation before blocking

---

 lib/cobalt/internal.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c
index f44ab71..5e2f0bd 100644
--- a/lib/cobalt/internal.c
+++ b/lib/cobalt/internal.c
@@ -51,7 +51,7 @@ int __cobalt_thread_stat(pid_t pid, struct cobalt_threadstat 
*stat)
 
 int __cobalt_thread_join(pthread_t thread)
 {
-       int ret;
+       int ret, oldtype;
 
        /*
         * Serialize with the regular task exit path, so that no call
@@ -70,6 +70,9 @@ int __cobalt_thread_join(pthread_t thread)
         * -EPERM may be received because the current context is not a
         * Xenomai thread.
         *
+        * -EINVAL is received in case the target is not a joinable
+        * thread (i.e. detached).
+        *
         * Zero is unexpected.
         *
         * CAUTION: this service joins a thread Cobat-wise only, not
@@ -77,11 +80,15 @@ int __cobalt_thread_join(pthread_t thread)
         * cleanups, __STD(pthread_join()) should be paired with this
         * call.
         */
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
        do
                ret = XENOMAI_SKINCALL1(__cobalt_muxid,
                                        sc_cobalt_thread_join, thread);
        while (ret == -EINTR);
 
+       pthread_setcanceltype(oldtype, NULL);
+
        return ret;
 }
 
@@ -174,8 +181,8 @@ int cobalt_monitor_enter(cobalt_monitor_t *mon)
 {
        struct cobalt_monitor_data *datp;
        unsigned long status;
+       int ret, oldtype;
        xnhandle_t cur;
-       int ret;
 
        /*
         * Assumptions on entry:
@@ -196,6 +203,8 @@ int cobalt_monitor_enter(cobalt_monitor_t *mon)
                return 0;
        }
 syscall:
+       pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &oldtype);
+
        /*
         * Jump to kernel to wait for entry. We redo in case of
         * interrupt.
@@ -206,6 +215,8 @@ syscall:
                                        mon);
        while (ret == -EINTR);
 
+       pthread_setcanceltype(oldtype, NULL);
+
        return ret;
 }
 


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

Reply via email to