Module: xenomai-forge Branch: next Commit: 7ed0572c6b80d700d56a676337c8a3828eadce65 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=7ed0572c6b80d700d56a676337c8a3828eadce65
Author: Philippe Gerum <r...@xenomai.org> Date: Thu May 22 15:16:54 2014 +0200 copperplate/internal: reorder head code for copperplate_create_thread() Once the prologue handler has run successfully from the thread trampoline, the client code may assume that we can't fail spawning the child thread anymore, which guarantees that copperplate_create_thread() will return a success code after this point. This way, any thread finalizer installed by the prologue handler won't conflict with the cleanup code the client may run whenever copperplate_create_thread() fails. --- lib/copperplate/internal.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/copperplate/internal.c b/lib/copperplate/internal.c index b57b529..a0c158a 100644 --- a/lib/copperplate/internal.c +++ b/lib/copperplate/internal.c @@ -194,23 +194,33 @@ static void *thread_trampoline(void *arg) * structure early on. */ _cta = *cta; - ret = cta->prologue(cta->arg); - cta->__reserved.status = ret; - if (ret) - goto fail; ret = __bt(-__RT(sem_init(&released, 0, 0))); if (ret) { ret = -errno; cta->__reserved.status = ret; + warning("lack of resources for core thread, %s", symerror(ret)); goto fail; } cta->__reserved.released = &released; + ret = cta->prologue(cta->arg); + cta->__reserved.status = ret; + if (ret) { + __RT(sem_destroy(&released)); + backtrace_check(); + goto fail; + } + /* - * CAUTION: over Cobalt, we have to switch back to primary - * mode _before_ releasing the parent thread, so that proper - * priority rules apply between the parent and child threads. + * CAUTION: Once the prologue handler has run successfully, + * the client code may assume that we can't fail spawning the + * child thread anymore, which guarantees that + * copperplate_create_thread() will return a success code + * after this point. This is important so that any thread + * finalizer installed by the prologue handler won't conflict + * with the cleanup code the client may run whenever + * copperplate_create_thread() fails. */ prepare_wait_corespec(); __RT(sem_post(&cta->__reserved.warm)); @@ -223,7 +233,6 @@ static void *thread_trampoline(void *arg) return _cta.run(_cta.arg); fail: - backtrace_check(); __RT(sem_post(&cta->__reserved.warm)); return (void *)(long)ret; _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git