:: rt_printf with daemonized task
-------- Original Message --------
Subject: Re: :: rt_printf with daemonized task (20-Okt-2009 11:33) From: Jan Kiszka <[email protected]> To: [email protected]
Quoted 8 lines
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.
---
--- 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: [email protected]
Cc: [email protected]
[email protected]
Review
Quoted 6 lines · [email protected] wrote:
(quoted diff) +6
-0+ while (*pbuffer) { + if (*pbuffer == my_buffer) + pbuffer = &(*pbuffer)->next; + else + cleanup_buffer(*pbuffer); + }
Looks like an infinite loop if *pbuffer != my_buffer, no?
Signature · 1 line
Gilles.
Quoted 10 lines · Gilles Chanteperdrix
Review
Quoted 6 lines · [email protected] wrote:
(quoted diff) +6
-0+ while (*pbuffer) { + if (*pbuffer == my_buffer) + pbuffer = &(*pbuffer)->next; + else + cleanup_buffer(*pbuffer); + }Looks like an infinite loop if *pbuffer !=
my_buffer, no?
No, cleanup_buffer is shrinking the list until it's NULL (or only my_buffer).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 13 lines · [email protected] wrote:
-------- Original Message --------
Subject: Re: :: rt_printf with daemonized task (20-Okt-2009 11:33) From: Jan Kiszka <[email protected]> To: [email protected]Quoted 4 lines
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.
Quoted 6 lines
Quoted 3 lines
HTH,
Janok, here is my next trial for a proper patch
That format looks good.
Thanks,
Jan
Quoted 70 lines
Oliver
----------------------------------------------------------------------------------------------
Subject : Fork-save use of
rt_printFork save initialisation of
rt_printlibrary, necessary child initialisation are done viapthread_atfork()when child process is started.Signed-off-by Oliver Schlenker <oliver.schlenker <at> sm motion control.de>---
rt_print.c.forkonly renamed from rt_print.c.original +29
-4} } -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: [email protected]
Cc: [email protected]
[email protected]
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux