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

Author: Gilles Chanteperdrix <gilles.chanteperd...@xenomai.org>
Date:   Tue Jan 12 13:34:28 2010 +0100

rtdk: various fixes.

When exiting a process, rtdk buffers are not flushed. Fix that by
introducing a destructor for the library which flushes the buffers.

When forking, if the main thread has an rt_printf buffer, it is reused by
the child, which is a good thing, however, it is not emptied, so could cause
the same message to be printed twice. Fix that by emptying the main thread
buffer upon fork.

---

 src/rtdk/init.c     |    5 +++++
 src/rtdk/internal.h |    1 +
 src/rtdk/rt_print.c |   20 ++++++++++++++++++++
 3 files changed, 26 insertions(+), 0 deletions(-)

diff --git a/src/rtdk/init.c b/src/rtdk/init.c
index 2084c73..b864175 100644
--- a/src/rtdk/init.c
+++ b/src/rtdk/init.c
@@ -22,3 +22,8 @@ static __attribute__ ((constructor)) void __init_rtdk(void)
 {
        __rt_print_init();
 }
+
+static __attribute__ ((destructor)) void __exit_rtdk(void)
+{
+       __rt_print_exit();
+}
diff --git a/src/rtdk/internal.h b/src/rtdk/internal.h
index bd15b2d..345d4fa 100644
--- a/src/rtdk/internal.h
+++ b/src/rtdk/internal.h
@@ -23,6 +23,7 @@
 #include <sys/time.h>
 
 void __rt_print_init(void);
+void __rt_print_exit(void);
 
 void __real_free(void *ptr);
 void *__real_malloc(size_t size);
diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
index 1d2b70a..fc170d0 100644
--- a/src/rtdk/rt_print.c
+++ b/src/rtdk/rt_print.c
@@ -29,6 +29,7 @@
 
 #include <rtdk.h>
 #include <asm/xenomai/system.h>
+#include <asm-generic/stacksize.h>
 
 #define RT_PRINT_BUFFER_ENV            "RT_PRINT_BUFFER"
 #define RT_PRINT_DEFAULT_BUFFER                16*1024
@@ -464,6 +465,15 @@ static void forked_child_init(void)
        struct print_buffer *my_buffer = pthread_getspecific(buffer_key);
        struct print_buffer **pbuffer = &first_buffer;
 
+       if (my_buffer) {
+               /* Any content of my_buffer should be printed by our parent,
+                  not us. */
+               memset(my_buffer->ring, 0, my_buffer->size);
+
+               my_buffer->read_pos  = 0;
+               my_buffer->write_pos = 0;
+       }
+
        /* re-init to avoid finding it locked by some parent thread */
        pthread_mutex_init(&buffer_lock, NULL);
 
@@ -518,3 +528,13 @@ void __rt_print_init(void)
        spawn_printer_thread();
        pthread_atfork(NULL, NULL, forked_child_init);
 }
+
+void __rt_print_exit(void)
+{
+       if (buffers) {
+               /* Flush the buffers. Do not call print_buffers here
+                * since we do not know if our stack is big enough. */
+               nanosleep(&print_period, NULL);
+               nanosleep(&print_period, NULL);
+       }
+}


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

Reply via email to