[Xenomai-git] Philippe Gerum : cobalt/thread, posix: clearly distinguish exit vs finalization handlers

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: master
Commit: 439eb3f33b19a2e7e5064e79777de4c23474cbf1
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=439eb3f33b19a2e7e5064e79777de4c23474cbf1

Author: Philippe Gerum 
Date:   Wed Jul 31 12:25:20 2013 +0200

cobalt/thread, posix: clearly distinguish exit vs finalization handlers

The exit handler is called locklessly with interrupts enabled, for
dropping all resources allocated by the personality, except the TCB
which may still be referenced for accessing resources maintained by
the Cobalt core.

The finalization handler shall drop the TCB and may therefore assume
that no further reference to this memory may be done afterwards from
the Cobalt core.

---

 include/cobalt/kernel/shadow.h |4 ++--
 kernel/cobalt/pod.c|4 ++--
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   35 ---
 kernel/cobalt/posix/thread.h   |2 +-
 kernel/cobalt/shadow.c |6 +++---
 6 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/include/cobalt/kernel/shadow.h b/include/cobalt/kernel/shadow.h
index 5afadf8..5f63d55 100644
--- a/include/cobalt/kernel/shadow.h
+++ b/include/cobalt/kernel/shadow.h
@@ -42,7 +42,7 @@ struct xnpersonality {
void (*detach_process)(struct xnshadow_ppd *ppd);
struct xnpersonality *(*map_thread)(struct xnthread *thread);
struct xnpersonality *(*exit_thread)(struct xnthread *thread);
-   struct xnpersonality *(*unmap_thread)(struct xnthread *thread);
+   struct xnpersonality *(*finalize_thread)(struct xnthread 
*thread);
} ops;
struct module *module;
 };
@@ -89,7 +89,7 @@ int xnshadow_map_user(struct xnthread *thread,
 int xnshadow_map_kernel(struct xnthread *thread,
struct completion *done);
 
-void xnshadow_unmap(struct xnthread *thread);
+void xnshadow_finalize(struct xnthread *thread);
 
 int xnshadow_harden(void);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 89ba956..5ff2a9d 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -696,8 +696,8 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
 
xnsched_forget(thread);
xnthread_cleanup(thread);
-   /* Unmap last since this incurs releasing the TCB. */
-   xnshadow_unmap(thread);
+   /* Finalize last since this incurs releasing the TCB. */
+   xnshadow_finalize(thread);
 
if (xnthread_test_state(sched->curr, XNROOT))
xnfreesync();
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 84f7c53..cf8c3a9 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -365,7 +365,7 @@ struct xnpersonality cobalt_personality = {
.attach_process = cobalt_process_attach,
.detach_process = cobalt_process_detach,
.exit_thread = cobalt_thread_exit,
-   .unmap_thread = cobalt_thread_unmap,
+   .finalize_thread = cobalt_thread_finalize,
},
 };
 EXPORT_SYMBOL_GPL(cobalt_personality);
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index bd6f3f1..7caf10f 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -182,14 +182,6 @@ thread_find_local(const struct cobalt_local_hkey *hkey)
return thread;
 }
 
-static void thread_destroy(struct cobalt_thread *thread)
-{
-   list_del(&thread->link);
-   xnsynch_destroy(&thread->monitor_synch);
-   xnsynch_destroy(&thread->sigwait);
-   xnheap_schedule_free(&kheap, thread, &thread->link);
-}
-
 struct cobalt_thread *cobalt_thread_find(pid_t pid) /* nklocked, IRQs off */
 {
struct global_thread_hash *gslot;
@@ -218,17 +210,20 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
cobalt_mark_deleted(thread);
cobalt_signal_flush(thread);
cobalt_timer_flush(thread);
+   xnsynch_destroy(&thread->monitor_synch);
+   xnsynch_destroy(&thread->sigwait);
 
/* We don't stack over any personality, no chaining. */
return NULL;
 }
 
-struct xnpersonality *cobalt_thread_unmap(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
 {
struct cobalt_thread *thread;
 
thread = container_of(zombie, struct cobalt_thread, threadbase);
-   thread_destroy(thread);
+   list_del(&thread->link);
+   xnheap_schedule_free(&kheap, thread, &thread->link);
 
return NULL;
 }
@@ -473,24 +468,26 @@ static inline int pthread_create(struct cobalt_thread 
**thread_p, const pthread_
if (thread->attr.policy == SCHED_RR)
xnpod_set_thread_tslice(&thread->threadbase, cobalt_time_slice);
 
-   xnlock_get_irqsave(&nklock, s);
-   thread->container = &cobalt_kqueues(0)->threadq;
- 

[Xenomai-git] Philippe Gerum : cobalt/thread, posix: clearly distinguish exit vs finalization handlers

2013-08-10 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 439eb3f33b19a2e7e5064e79777de4c23474cbf1
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=439eb3f33b19a2e7e5064e79777de4c23474cbf1

Author: Philippe Gerum 
Date:   Wed Jul 31 12:25:20 2013 +0200

cobalt/thread, posix: clearly distinguish exit vs finalization handlers

The exit handler is called locklessly with interrupts enabled, for
dropping all resources allocated by the personality, except the TCB
which may still be referenced for accessing resources maintained by
the Cobalt core.

The finalization handler shall drop the TCB and may therefore assume
that no further reference to this memory may be done afterwards from
the Cobalt core.

---

 include/cobalt/kernel/shadow.h |4 ++--
 kernel/cobalt/pod.c|4 ++--
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   35 ---
 kernel/cobalt/posix/thread.h   |2 +-
 kernel/cobalt/shadow.c |6 +++---
 6 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/include/cobalt/kernel/shadow.h b/include/cobalt/kernel/shadow.h
index 5afadf8..5f63d55 100644
--- a/include/cobalt/kernel/shadow.h
+++ b/include/cobalt/kernel/shadow.h
@@ -42,7 +42,7 @@ struct xnpersonality {
void (*detach_process)(struct xnshadow_ppd *ppd);
struct xnpersonality *(*map_thread)(struct xnthread *thread);
struct xnpersonality *(*exit_thread)(struct xnthread *thread);
-   struct xnpersonality *(*unmap_thread)(struct xnthread *thread);
+   struct xnpersonality *(*finalize_thread)(struct xnthread 
*thread);
} ops;
struct module *module;
 };
@@ -89,7 +89,7 @@ int xnshadow_map_user(struct xnthread *thread,
 int xnshadow_map_kernel(struct xnthread *thread,
struct completion *done);
 
-void xnshadow_unmap(struct xnthread *thread);
+void xnshadow_finalize(struct xnthread *thread);
 
 int xnshadow_harden(void);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 89ba956..5ff2a9d 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -696,8 +696,8 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
 
xnsched_forget(thread);
xnthread_cleanup(thread);
-   /* Unmap last since this incurs releasing the TCB. */
-   xnshadow_unmap(thread);
+   /* Finalize last since this incurs releasing the TCB. */
+   xnshadow_finalize(thread);
 
if (xnthread_test_state(sched->curr, XNROOT))
xnfreesync();
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 84f7c53..cf8c3a9 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -365,7 +365,7 @@ struct xnpersonality cobalt_personality = {
.attach_process = cobalt_process_attach,
.detach_process = cobalt_process_detach,
.exit_thread = cobalt_thread_exit,
-   .unmap_thread = cobalt_thread_unmap,
+   .finalize_thread = cobalt_thread_finalize,
},
 };
 EXPORT_SYMBOL_GPL(cobalt_personality);
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index bd6f3f1..7caf10f 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -182,14 +182,6 @@ thread_find_local(const struct cobalt_local_hkey *hkey)
return thread;
 }
 
-static void thread_destroy(struct cobalt_thread *thread)
-{
-   list_del(&thread->link);
-   xnsynch_destroy(&thread->monitor_synch);
-   xnsynch_destroy(&thread->sigwait);
-   xnheap_schedule_free(&kheap, thread, &thread->link);
-}
-
 struct cobalt_thread *cobalt_thread_find(pid_t pid) /* nklocked, IRQs off */
 {
struct global_thread_hash *gslot;
@@ -218,17 +210,20 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
cobalt_mark_deleted(thread);
cobalt_signal_flush(thread);
cobalt_timer_flush(thread);
+   xnsynch_destroy(&thread->monitor_synch);
+   xnsynch_destroy(&thread->sigwait);
 
/* We don't stack over any personality, no chaining. */
return NULL;
 }
 
-struct xnpersonality *cobalt_thread_unmap(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
 {
struct cobalt_thread *thread;
 
thread = container_of(zombie, struct cobalt_thread, threadbase);
-   thread_destroy(thread);
+   list_del(&thread->link);
+   xnheap_schedule_free(&kheap, thread, &thread->link);
 
return NULL;
 }
@@ -473,24 +468,26 @@ static inline int pthread_create(struct cobalt_thread 
**thread_p, const pthread_
if (thread->attr.policy == SCHED_RR)
xnpod_set_thread_tslice(&thread->threadbase, cobalt_time_slice);
 
-   xnlock_get_irqsave(&nklock, s);
-   thread->container = &cobalt_kqueues(0)->threadq;
-   

[Xenomai-git] Philippe Gerum : cobalt/thread, posix: clearly distinguish exit vs finalization handlers

2013-07-31 Thread git repository hosting
Module: xenomai-forge
Branch: next
Commit: 2e43d57c6a62d67e4e8905d1341bad8b134ad516
URL:
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=2e43d57c6a62d67e4e8905d1341bad8b134ad516

Author: Philippe Gerum 
Date:   Wed Jul 31 12:25:20 2013 +0200

cobalt/thread, posix: clearly distinguish exit vs finalization handlers

The exit handler is called locklessly with interrupts enabled, for
dropping all resources allocated by the personality, except the TCB
which may still be referenced for accessing resources maintained by
the Cobalt core.

The finalization handler shall drop the TCB and may therefore assume
that no further reference to this memory may be done afterwards from
the Cobalt core.

---

 include/cobalt/kernel/shadow.h |4 ++--
 kernel/cobalt/pod.c|4 ++--
 kernel/cobalt/posix/syscall.c  |2 +-
 kernel/cobalt/posix/thread.c   |   35 ---
 kernel/cobalt/posix/thread.h   |2 +-
 kernel/cobalt/shadow.c |6 +++---
 6 files changed, 25 insertions(+), 28 deletions(-)

diff --git a/include/cobalt/kernel/shadow.h b/include/cobalt/kernel/shadow.h
index 5afadf8..5f63d55 100644
--- a/include/cobalt/kernel/shadow.h
+++ b/include/cobalt/kernel/shadow.h
@@ -42,7 +42,7 @@ struct xnpersonality {
void (*detach_process)(struct xnshadow_ppd *ppd);
struct xnpersonality *(*map_thread)(struct xnthread *thread);
struct xnpersonality *(*exit_thread)(struct xnthread *thread);
-   struct xnpersonality *(*unmap_thread)(struct xnthread *thread);
+   struct xnpersonality *(*finalize_thread)(struct xnthread 
*thread);
} ops;
struct module *module;
 };
@@ -89,7 +89,7 @@ int xnshadow_map_user(struct xnthread *thread,
 int xnshadow_map_kernel(struct xnthread *thread,
struct completion *done);
 
-void xnshadow_unmap(struct xnthread *thread);
+void xnshadow_finalize(struct xnthread *thread);
 
 int xnshadow_harden(void);
 
diff --git a/kernel/cobalt/pod.c b/kernel/cobalt/pod.c
index 89ba956..5ff2a9d 100644
--- a/kernel/cobalt/pod.c
+++ b/kernel/cobalt/pod.c
@@ -696,8 +696,8 @@ static void cleanup_thread(struct xnthread *thread) /* 
nklock held, irqs off */
 
xnsched_forget(thread);
xnthread_cleanup(thread);
-   /* Unmap last since this incurs releasing the TCB. */
-   xnshadow_unmap(thread);
+   /* Finalize last since this incurs releasing the TCB. */
+   xnshadow_finalize(thread);
 
if (xnthread_test_state(sched->curr, XNROOT))
xnfreesync();
diff --git a/kernel/cobalt/posix/syscall.c b/kernel/cobalt/posix/syscall.c
index 84f7c53..cf8c3a9 100644
--- a/kernel/cobalt/posix/syscall.c
+++ b/kernel/cobalt/posix/syscall.c
@@ -365,7 +365,7 @@ struct xnpersonality cobalt_personality = {
.attach_process = cobalt_process_attach,
.detach_process = cobalt_process_detach,
.exit_thread = cobalt_thread_exit,
-   .unmap_thread = cobalt_thread_unmap,
+   .finalize_thread = cobalt_thread_finalize,
},
 };
 EXPORT_SYMBOL_GPL(cobalt_personality);
diff --git a/kernel/cobalt/posix/thread.c b/kernel/cobalt/posix/thread.c
index bd6f3f1..7caf10f 100644
--- a/kernel/cobalt/posix/thread.c
+++ b/kernel/cobalt/posix/thread.c
@@ -182,14 +182,6 @@ thread_find_local(const struct cobalt_local_hkey *hkey)
return thread;
 }
 
-static void thread_destroy(struct cobalt_thread *thread)
-{
-   list_del(&thread->link);
-   xnsynch_destroy(&thread->monitor_synch);
-   xnsynch_destroy(&thread->sigwait);
-   xnheap_schedule_free(&kheap, thread, &thread->link);
-}
-
 struct cobalt_thread *cobalt_thread_find(pid_t pid) /* nklocked, IRQs off */
 {
struct global_thread_hash *gslot;
@@ -218,17 +210,20 @@ struct xnpersonality *cobalt_thread_exit(struct xnthread 
*curr)
cobalt_mark_deleted(thread);
cobalt_signal_flush(thread);
cobalt_timer_flush(thread);
+   xnsynch_destroy(&thread->monitor_synch);
+   xnsynch_destroy(&thread->sigwait);
 
/* We don't stack over any personality, no chaining. */
return NULL;
 }
 
-struct xnpersonality *cobalt_thread_unmap(struct xnthread *zombie) /* 
nklocked, IRQs off */
+struct xnpersonality *cobalt_thread_finalize(struct xnthread *zombie) /* 
nklocked, IRQs off */
 {
struct cobalt_thread *thread;
 
thread = container_of(zombie, struct cobalt_thread, threadbase);
-   thread_destroy(thread);
+   list_del(&thread->link);
+   xnheap_schedule_free(&kheap, thread, &thread->link);
 
return NULL;
 }
@@ -473,24 +468,26 @@ static inline int pthread_create(struct cobalt_thread 
**thread_p, const pthread_
if (thread->attr.policy == SCHED_RR)
xnpod_set_thread_tslice(&thread->threadbase, cobalt_time_slice);
 
-   xnlock_get_irqsave(&nklock, s);
-   thread->container = &cobalt_kqueues(0)->threadq;
-