Module: xenomai-3
Branch: stable-3.0.x
Commit: 67db5a44c8aabc902227401815feaae2036de0f2
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=67db5a44c8aabc902227401815feaae2036de0f2

Author: Philippe Gerum <r...@xenomai.org>
Date:   Tue Mar  1 08:36:18 2016 +0100

cobalt/thread: do not demote kthreads when cancelling

There is no point in switching a kthread to weak scheduling when
cancelling it, as it must reach a cancellation point asap as part of
its work loop anyway. Would it omit testing for cancellation, weak
scheduling would not help enforcing the exit request anyway.

---

 kernel/cobalt/thread.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/kernel/cobalt/thread.c b/kernel/cobalt/thread.c
index a8edece..5f404ed 100644
--- a/kernel/cobalt/thread.c
+++ b/kernel/cobalt/thread.c
@@ -1566,16 +1566,21 @@ check_self_cancel:
                return;
        }
 
-       __xnthread_demote(thread);
-
        /*
-        * A userland thread undergoing the weak scheduling policy is
-        * unlikely to issue Cobalt syscalls frequently, which may
-        * defer cancellation significantly: send it a regular
-        * termination signal too.
+        * Force the non-current thread to exit:
+        *
+        * - unblock a user thread, switch it to weak scheduling,
+        * then send it SIGTERM.
+        *
+        * - just unblock a kernel thread, it is expected to reach a
+        * cancellation point soon after
+        * (i.e. xnthread_test_cancel()).
         */
-       if (xnthread_test_state(thread, XNWEAK|XNUSER) == (XNWEAK|XNUSER))
+       if (xnthread_test_state(thread, XNUSER)) {
+               __xnthread_demote(thread);
                xnthread_signal(thread, SIGTERM, 0);
+       } else
+               __xnthread_kick(thread);
 out:
        xnlock_put_irqrestore(&nklock, s);
 


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

Reply via email to