Module: xenomai-head
Branch: master
Commit: efac990fee3b84ba8951c9acd5449d30dc940048
URL:    
http://git.xenomai.org/?p=xenomai-head.git;a=commit;h=efac990fee3b84ba8951c9acd5449d30dc940048

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Tue Jun 28 22:22:50 2011 +0200

posix: only use rt_printf when in primary mode

---

 include/rtdk.h              |    1 +
 src/skins/common/rt_print.c |   10 ++++++++++
 src/skins/posix/printf.c    |   20 ++++++++++++++++++--
 3 files changed, 29 insertions(+), 2 deletions(-)

diff --git a/include/rtdk.h b/include/rtdk.h
index b5c0be9..905d35a 100644
--- a/include/rtdk.h
+++ b/include/rtdk.h
@@ -59,6 +59,7 @@ int rt_print_init(size_t buffer_size, const char *name);
 void rt_print_cleanup(void);
 void rt_print_auto_init(int enable);
 const char *rt_print_buffer_name(void);
+void rt_print_flush_buffers(void);
 
 void assert_nrt(void);
 
diff --git a/src/skins/common/rt_print.c b/src/skins/common/rt_print.c
index 42d85d3..356347c 100644
--- a/src/skins/common/rt_print.c
+++ b/src/skins/common/rt_print.c
@@ -395,6 +395,16 @@ const char *rt_print_buffer_name(void)
 }
 
 /* *** Deferred Output Management *** */
+void rt_print_flush_buffers(void)
+{
+       assert_nrt();
+
+       pthread_mutex_lock(&buffer_lock);
+
+       print_buffers();
+
+       pthread_mutex_unlock(&buffer_lock);
+}
 
 static void cleanup_buffer(struct print_buffer *buffer)
 {
diff --git a/src/skins/posix/printf.c b/src/skins/posix/printf.c
index e778bc7..f2b950a 100644
--- a/src/skins/posix/printf.c
+++ b/src/skins/posix/printf.c
@@ -1,10 +1,20 @@
 #include <stdio.h>
 #include <syslog.h>
 #include <rtdk.h>
+#include <asm-generic/bits/current.h>
 
 int __wrap_vfprintf(FILE *stream, const char *fmt, va_list args)
 {
-       return rt_vfprintf(stream, fmt, args);
+       if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
+                    !(xeno_get_current_mode() & XNRELAX))) {
+
+               rt_fprintf(stderr, "current: %lu, mode: 0x%08lx\n",
+                          xeno_get_current(), xeno_get_current_mode());
+               return rt_vfprintf(stream, fmt, args);
+       } else {
+               rt_print_flush_buffers();
+               return vfprintf(stream, fmt, args);
+       }
 }
 
 int __wrap_vprintf(const char *fmt, va_list args)
@@ -38,7 +48,13 @@ int __wrap_printf(const char *fmt, ...)
 
 void __wrap_vsyslog(int priority, const char *fmt, va_list ap)
 {
-       return rt_vsyslog(priority, fmt, ap);
+       if (unlikely(xeno_get_current() != XN_NO_HANDLE &&
+                    !(xeno_get_current_mode() & XNRELAX)))
+               return rt_vsyslog(priority, fmt, ap);
+       else {
+               rt_print_flush_buffers();
+               vsyslog(priority, fmt, ap);
+       }
 }
 
 void __wrap_syslog(int priority, const char *fmt, ...)


_______________________________________________
Xenomai-git mailing list
Xenomai-git@gna.org
https://mail.gna.org/listinfo/xenomai-git

Reply via email to