[Xenomai-git] Philippe Gerum : lib/cobalt: simplify checks for secondary mode
Module: xenomai-3 Branch: wip/dovetail Commit: e0f1cd9568e3f00b2a148b6902327fc36346c25d URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e0f1cd9568e3f00b2a148b6902327fc36346c25d Author: Philippe GerumDate: 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 _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
[Xenomai-git] Philippe Gerum : lib/cobalt: simplify checks for secondary mode
Module: xenomai-3 Branch: next Commit: e0f1cd9568e3f00b2a148b6902327fc36346c25d URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=e0f1cd9568e3f00b2a148b6902327fc36346c25d Author: Philippe GerumDate: 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 _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
[Xenomai-git] Philippe Gerum : lib/cobalt: simplify checks for secondary mode
Module: xenomai-3 Branch: wip/prioceil Commit: d054cdb53e73832c292cb28a9b043d6b9eae3c5e URL: http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=d054cdb53e73832c292cb28a9b043d6b9eae3c5e Author: Philippe GerumDate: 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 _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
[Xenomai-git] Philippe Gerum : lib/cobalt: simplify checks for secondary mode
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 GerumDate: 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 _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