From: oliver.schlenker@domain.hid
To: jan.kiszka@domain.hid
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] :: rt_printf with daemonized task
Date: Tue, 20 Oct 2009 10:03:04 +0000 [thread overview]
Message-ID: <0000AE71.4ADDA6F7@domain.hid> (raw)
-------- Original Message --------
Subject: Re: :: rt_printf with daemonized task (20-Okt-2009 11:33)
From: Jan Kiszka <jan.kiszka@siemens.com>
To: oliver.schlenker@smmotioncontrol.de
>
> See http://thread.gmane.org/gmane.linux.real-time.xenomai.devel/6571 for
> an example of a patch that may (but need not) be generated via git. What
> counts is the format: proper title, a few lines of description, signed-off.
>
> HTH,
> Jan
>
ok, here is my next trial for a proper patch
Oliver
----------------------------------------------------------------------------------------------
Subject : Fork-save use of rt_print
Fork save initialisation of rt_print library, necessary child initialisation are
done via pthread_atfork() when child process is started.
Signed-off-by: Oliver Schlenker <oliver.schlenker <at> sm motion control.de>
---
--- rt_print.c.original 2008-09-10 10:36:27.000000000 +0200
+++ rt_print.c.forkonly 2009-10-16 16:19:25.949289800 +0200
}
}
-void __rt_print_init(void)
+static void spawn_printer_thread(void)
{
pthread_attr_t thattr;
+
+ pthread_attr_init(&thattr);
+ pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
+ pthread_create(&__printer_thread, &thattr, printer_loop, NULL);
+}
+
+static void forked_child_init(void)
+{
+ struct print_buffer *my_buffer = pthread_getspecific(__buffer_key);
+ struct print_buffer **pbuffer = &__first_buffer;
+
+ /* re-init to avoid finding it locked by some parent thread */
+ pthread_mutex_init(&__buffer_lock, NULL);
+
+ while (*pbuffer) {
+ if (*pbuffer == my_buffer)
+ pbuffer = &(*pbuffer)->next;
+ else
+ cleanup_buffer(*pbuffer);
+ }
+
+ spawn_printer_thread();
+}
+
+void __rt_print_init(void)
+{
const char *value_str;
unsigned long long period;
pthread_mutex_init(&__buffer_lock, NULL);
pthread_key_create(&__buffer_key, (void (*)(void*))cleanup_buffer);
- pthread_attr_init(&thattr);
- pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
- pthread_create(&__printer_thread, &thattr, printer_loop, NULL);
+ spawn_printer_thread();
+ pthread_atfork(NULL, NULL, forked_child_init);
}
To: jan.kiszka@siemens.com
Cc: gilles.chanteperdrix@xenomai.org
xenomai-help@gna.org
next reply other threads:[~2009-10-20 10:03 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-10-20 10:03 oliver.schlenker [this message]
2009-10-20 16:01 ` [Xenomai-help] :: rt_printf with daemonized task Gilles Chanteperdrix
2009-10-20 16:07 ` Jan Kiszka
2009-10-20 16:11 ` Jan Kiszka
-- strict thread matches above, loose matches on Subject: below --
2009-10-20 9:26 oliver.schlenker
2009-10-20 9:33 ` Jan Kiszka
2009-10-19 13:14 oliver.schlenker
2009-10-19 14:00 ` Jan Kiszka
2009-10-19 13:12 oliver.schlenker
2009-10-19 14:00 ` Jan Kiszka
2009-10-09 14:48 oliver.schlenker
2009-10-09 14:59 ` Jan Kiszka
2009-10-09 13:54 oliver.schlenker
2009-10-09 13:34 oliver.schlenker
2009-10-09 13:49 ` Gilles Chanteperdrix
2009-10-09 13:58 ` Jan Kiszka
2009-10-08 12:01 oliver.schlenker
2009-10-08 13:17 ` Jan Kiszka
2009-10-08 7:15 [Xenomai-help] " oliver.schlenker
2009-10-06 15:10 oliver.schlenker
2009-10-06 15:16 ` Gilles Chanteperdrix
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0000AE71.4ADDA6F7@domain.hid \
--to=oliver.schlenker@domain.hid \
--cc=jan.kiszka@domain.hid \
--cc=xenomai@xenomai.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.