Module: xenomai-forge Branch: next Commit: a1c6f1da95ea848ffe0dc13b5f9c6337b0b8e2b9 URL: http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=a1c6f1da95ea848ffe0dc13b5f9c6337b0b8e2b9
Author: Philippe Gerum <r...@xenomai.org> Date: Tue Jul 1 20:55:51 2014 +0200 lib/cobalt: centralize TSD setup --- lib/cobalt/current.c | 60 +++++++++++++++++++++++++++----------------------- lib/cobalt/current.h | 4 +--- lib/cobalt/thread.c | 9 +++----- 3 files changed, 37 insertions(+), 36 deletions(-) diff --git a/lib/cobalt/current.c b/lib/cobalt/current.c index d28fb29..061685d 100644 --- a/lib/cobalt/current.c +++ b/lib/cobalt/current.c @@ -33,21 +33,24 @@ xnhandle_t cobalt_current = XN_NO_HANDLE; __thread __attribute__ ((tls_model (CONFIG_XENO_TLS_MODEL))) struct xnthread_user_window *cobalt_current_window; -static inline void __cobalt_set_current(xnhandle_t current) +static inline void __cobalt_set_tsd(xnhandle_t current, unsigned long u_winoff) { + struct xnthread_user_window *window; + cobalt_current = current; + window = (void *)(cobalt_sem_heap[0] + u_winoff); + cobalt_current_window = window; + cobalt_commit_memory(cobalt_current_window); } -static void init_current_keys(void) +static inline void __cobalt_clear_tsd(void) { - pthread_atfork(NULL, NULL, &child_fork_handler); + cobalt_current = XN_NO_HANDLE; } -void cobalt_set_current_window(unsigned long offset) +static void init_current_keys(void) { - cobalt_current_window = (struct xnthread_user_window *) - (cobalt_sem_heap[0] + offset); - cobalt_commit_memory(cobalt_current_window); + pthread_atfork(NULL, NULL, &child_fork_handler); } #else /* !HAVE_TLS */ @@ -55,10 +58,22 @@ void cobalt_set_current_window(unsigned long offset) pthread_key_t cobalt_current_window_key; pthread_key_t cobalt_current_key; -static inline void __cobalt_set_current(xnhandle_t current) +static inline void __cobalt_set_tsd(xnhandle_t current, + unsigned long u_winoff) { + struct xnthread_user_window *window; + current = (current != XN_NO_HANDLE ? current : (xnhandle_t)(0)); pthread_setspecific(cobalt_current_key, (void *)current); + + window = (void *)(cobalt_sem_heap[0] + u_winoff); + pthread_setspecific(cobalt_current_window_key, window); + cobalt_commit_memory(window); +} + +static inline void __cobalt_clear_tsd(void) +{ + pthread_setspecific(cobalt_current_key, NULL); } static void init_current_keys(void) @@ -72,27 +87,17 @@ static void init_current_keys(void) err = pthread_key_create(&cobalt_current_window_key, NULL); if (err) { error_exit: - fprintf(stderr, "Xenomai: error creating TSD key: %s\n", - strerror(err)); + report_error("error creating TSD key: %s", strerror(err)); exit(EXIT_FAILURE); } } -void cobalt_set_current_window(unsigned long offset) -{ - struct xnthread_user_window *window; - - window = (void *)(cobalt_sem_heap[0] + offset); - pthread_setspecific(cobalt_current_window_key, window); - cobalt_commit_memory(window); -} - #endif /* !HAVE_TLS */ static void child_fork_handler(void) { if (cobalt_get_current() != XN_NO_HANDLE) - __cobalt_set_current(XN_NO_HANDLE); + __cobalt_clear_tsd(); } xnhandle_t cobalt_get_current_slow(void) @@ -105,18 +110,19 @@ xnhandle_t cobalt_get_current_slow(void) return err ? XN_NO_HANDLE : current; } -void cobalt_set_current(void) +void cobalt_set_tsd(unsigned long u_winoff) { xnhandle_t current; - int err; + int ret; - err = XENOMAI_SYSCALL1(sc_nucleus_current, ¤t); - if (err) { - fprintf(stderr, "Xenomai: error obtaining handle for current " - "thread: %s\n", strerror(-err)); + ret = XENOMAI_SYSCALL1(sc_nucleus_current, ¤t); + if (ret) { + report_error("error retrieving current handle: %s", + strerror(-ret)); exit(EXIT_FAILURE); } - __cobalt_set_current(current); + + __cobalt_set_tsd(current, u_winoff); } void cobalt_init_current_keys(void) diff --git a/lib/cobalt/current.h b/lib/cobalt/current.h index eeffef2..b3ad87e 100644 --- a/lib/cobalt/current.h +++ b/lib/cobalt/current.h @@ -90,8 +90,6 @@ static inline struct xnthread_user_window *cobalt_get_current_window(void) void cobalt_init_current_keys(void); -void cobalt_set_current(void); - -void cobalt_set_current_window(unsigned long offset); +void cobalt_set_tsd(unsigned long u_winoff); #endif /* _LIB_COBALT_CURRENT_H */ diff --git a/lib/cobalt/thread.c b/lib/cobalt/thread.c index 1ec55c2..547bef9 100644 --- a/lib/cobalt/thread.c +++ b/lib/cobalt/thread.c @@ -140,10 +140,8 @@ static void *cobalt_thread_trampoline(void *p) */ ret = -XENOMAI_SKINCALL5(__cobalt_muxid, sc_cobalt_thread_create, ptid, policy, ¶m_ex, personality, &u_winoff); - if (ret == 0) { - cobalt_set_current(); - cobalt_set_current_window(u_winoff); - } + if (ret == 0) + cobalt_set_tsd(u_winoff); /* * We must access anything we'll need from *iargs before @@ -664,8 +662,7 @@ int pthread_setschedparam_ex(pthread_t thread, if (ret == 0 && promoted) { commit_stack_memory(); cobalt_sigshadow_install_once(); - cobalt_set_current(); - cobalt_set_current_window(u_winoff); + cobalt_set_tsd(u_winoff); cobalt_thread_harden(); } _______________________________________________ Xenomai-git mailing list Xenomai-git@xenomai.org http://www.xenomai.org/mailman/listinfo/xenomai-git