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

Author: Philippe Gerum <r...@xenomai.org>
Date:   Wed Jul 31 16:00:50 2013 +0200

cobalt/thread: move finalizer call out of any critical section

There is no point in calling the thread finalization handler while
holding a lock, since it is supposed to release the TCB to some
allocator, which may incur some work.

Besides, the thread has entered an innocuous state long ago before the
finalizer is eventually called, so there is nothing to protect in its
TCB at this point.

Finalizers should do proper locking locally if need be.

---

 kernel/cobalt/pod.c          |    6 +++---
 kernel/cobalt/posix/thread.c |    6 +++---
 kernel/cobalt/shadow.c       |    2 --
 3 files changed, 6 insertions(+), 8 deletions(-)

diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 331dcf1..d90a2f6 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -782,8 +782,6 @@ static inline void cleanup_thread(struct xnthread *thread) 
/* nklock held, irqs
 
        xnsched_forget(thread);
        xnthread_deregister(thread);
-       /* Finalize last since this incurs releasing the TCB. */
-       xnshadow_finalize(thread);
 }
 
 void __xnpod_cleanup_thread(struct xnthread *thread)
@@ -806,9 +804,11 @@ void __xnpod_cleanup_thread(struct xnthread *thread)
 
        xnlock_get_irqsave(&nklock, s);
        cleanup_thread(thread);
-       xnfreesync();
        xnlock_put_irqrestore(&nklock, s);
 
+       /* Finalize last since this incurs releasing the TCB. */
+       xnshadow_finalize(thread);
+
        wake_up(&nkjoinq);
 }
 
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index 7caf10f..ac00826 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -212,18 +212,18 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
        cobalt_timer_flush(thread);
        xnsynch_destroy(&thread->monitor_synch);
        xnsynch_destroy(&thread->sigwait);
+       list_del(&thread->link);
 
        /* We don't stack over any personality, no chaining. */
        return NULL;
 }
 
-struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie)
 {
        struct cobalt_thread *thread;
 
        thread = container_of(zombie, struct cobalt_thread, threadbase);
-       list_del(&thread->link);
-       xnheap_schedule_free(&kheap, thread, &thread->link);
+       xnfree(thread);
 
        return NULL;
 }
diff --git a/kernel/cobalt/shadow.c b/kernel/cobalt/shadow.c
index 4d6b9eb..d43753f 100644
--- a/kernel/cobalt/shadow.c
+++ b/kernel/cobalt/shadow.c
@@ -1032,8 +1032,6 @@ void xnshadow_finalize(struct xnthread *thread)
 
        xnthread_run_handler(thread, finalize_thread);
 
-       xnthread_clear_state(thread, XNMAPPED);
-
        if (xnthread_test_state(thread, XNUSER)) {
                sys_ppd = xnsys_ppd_get(0);
                atomic_dec(&sys_ppd->refcnt);


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

Reply via email to