Module: xenomai-3 Branch: stable-3.0.x Commit: d054cdb53e73832c292cb28a9b043d6b9eae3c5e URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d054cdb53e73832c292cb28a9b043d6b9eae3c5e
Author: Philippe Gerum <[email protected]> Date: Fri Mar 18 12:00:55 2016 +0100 lib/cobalt: simplify checks for secondary mode Whether a current thread is currently running in primary/secondary mode can be checked by inspecting the status of the XNRELAX bit in the thread's u_window. The lack of u_window denotes a non-Xenomai, regular thread which for which the current mode is always relaxed. A thread's handle and its u_window area are tightly coupled: the latter has to be valid for any thread with a valid handle. Introduce cobalt_is_relaxed() for testing the current mode, and fixup all open coded versions of this routine. In addition, assert_nrt_fast() is marked as deprecated, since assert_nrt() is not a slow call anymore. --- include/cobalt/stdio.h | 1 + lib/cobalt/assert_context.c | 14 +++----------- lib/cobalt/internal.c | 4 +--- lib/cobalt/internal.h | 7 ++++++- lib/cobalt/printf.c | 27 +++++++++------------------ 5 files changed, 20 insertions(+), 33 deletions(-) diff --git a/include/cobalt/stdio.h b/include/cobalt/stdio.h index f0c289d..0d97b83 100644 --- a/include/cobalt/stdio.h +++ b/include/cobalt/stdio.h @@ -114,6 +114,7 @@ void rt_print_flush_buffers(void); void assert_nrt(void); +__attribute__((__deprecated__)) void assert_nrt_fast(void); #ifdef __cplusplus diff --git a/lib/cobalt/assert_context.c b/lib/cobalt/assert_context.c index da5f2b0..2085953 100644 --- a/lib/cobalt/assert_context.c +++ b/lib/cobalt/assert_context.c @@ -45,21 +45,13 @@ static void assert_nrt_inner(void) void assert_nrt(void) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) assert_nrt_inner(); } -/* - * Note: Works without syscalls but may not catch all errors when used inside - * TSD destructors (as registered via pthread_key_create) when TLS support - * (__thread) is disabled. - */ -void assert_nrt_fast(void) +void assert_nrt_fast(void) /* OBSOLETE */ { - if (cobalt_get_current_fast() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) - assert_nrt_inner(); + assert_nrt(); } /* Memory allocation services */ diff --git a/lib/cobalt/internal.c b/lib/cobalt/internal.c index 9220237..5b89db5 100644 --- a/lib/cobalt/internal.c +++ b/lib/cobalt/internal.c @@ -54,9 +54,7 @@ void cobalt_thread_harden(void) void cobalt_thread_relax(void) { - int status = cobalt_get_current_mode(); - - if ((status & XNRELAX) == 0) + if (!cobalt_is_relaxed()) XENOMAI_SYSCALL1(sc_cobalt_migrate, COBALT_SECONDARY); } diff --git a/lib/cobalt/internal.h b/lib/cobalt/internal.h index 69ec7d1..fee3fe1 100644 --- a/lib/cobalt/internal.h +++ b/lib/cobalt/internal.h @@ -27,7 +27,10 @@ extern void *cobalt_umm_private; extern void *cobalt_umm_shared; -void cobalt_sigshadow_install_once(void); +static inline int cobalt_is_relaxed(void) +{ + return cobalt_get_current_mode() & XNRELAX; +} static inline struct cobalt_mutex_state *mutex_get_state(struct cobalt_mutex_shadow *shadow) @@ -43,6 +46,8 @@ static inline atomic_t *mutex_get_ownerp(struct cobalt_mutex_shadow *shadow) return &mutex_get_state(shadow)->owner; } +void cobalt_sigshadow_install_once(void); + void cobalt_thread_init(void); int cobalt_thread_probe(pid_t pid); diff --git a/lib/cobalt/printf.c b/lib/cobalt/printf.c index 797a9b5..87cd5e2 100644 --- a/lib/cobalt/printf.c +++ b/lib/cobalt/printf.c @@ -730,8 +730,7 @@ done: COBALT_IMPL(int, vfprintf, (FILE *stream, const char *fmt, va_list args)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_vfprintf(stream, fmt, args); else { rt_print_flush_buffers(); @@ -770,8 +769,7 @@ COBALT_IMPL(int, printf, (const char *fmt, ...)) COBALT_IMPL(int, fputs, (const char *s, FILE *stream)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_fputs(s, stream); else { rt_print_flush_buffers(); @@ -781,8 +779,7 @@ COBALT_IMPL(int, fputs, (const char *s, FILE *stream)) COBALT_IMPL(int, puts, (const char *s)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_puts(s); else { rt_print_flush_buffers(); @@ -794,8 +791,7 @@ COBALT_IMPL(int, puts, (const char *s)) COBALT_IMPL(int, fputc, (int c, FILE *stream)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_fputc(c, stream); else { rt_print_flush_buffers(); @@ -805,8 +801,7 @@ COBALT_IMPL(int, fputc, (int c, FILE *stream)) COBALT_IMPL(int, putchar, (int c)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_putchar(c); else { rt_print_flush_buffers(); @@ -830,8 +825,7 @@ COBALT_IMPL(int, putchar, (int c)) COBALT_IMPL(size_t, fwrite, (const void *ptr, size_t size, size_t nmemb, FILE *stream)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_fwrite(ptr, size, nmemb, stream); else { rt_print_flush_buffers(); @@ -848,8 +842,7 @@ COBALT_IMPL(int, fclose, (FILE *stream)) COBALT_IMPL(void, vsyslog, (int priority, const char *fmt, va_list ap)) { - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return rt_vsyslog(priority, fmt, ap); else { rt_print_flush_buffers(); @@ -872,8 +865,7 @@ COBALT_IMPL(void, syslog, (int priority, const char *fmt, ...)) COBALT_IMPL(int, __vfprintf_chk, (FILE *f, int flag, const char *fmt, va_list ap)) { #ifdef CONFIG_XENO_FORTIFY - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return __rt_vfprintf_chk(f, flag, fmt, ap); else { rt_print_flush_buffers(); @@ -916,8 +908,7 @@ COBALT_IMPL(int, __printf_chk, (int flag, const char *fmt, ...)) COBALT_IMPL(void, __vsyslog_chk, (int pri, int flag, const char *fmt, va_list ap)) { #ifdef CONFIG_XENO_FORTIFY - if (cobalt_get_current() != XN_NO_HANDLE && - !(cobalt_get_current_mode() & XNRELAX)) + if (!cobalt_is_relaxed()) return __rt_vsyslog_chk(pri, flag, fmt, ap); else { rt_print_flush_buffers(); _______________________________________________ Xenomai-git mailing list [email protected] https://xenomai.org/mailman/listinfo/xenomai-git
