Module: xenomai-forge
Branch: next
Commit: 16e4422ad0dd57b0f9a1126db994e527733aa740
URL:    
http://git.xenomai.org/?p=xenomai-forge.git;a=commit;h=16e4422ad0dd57b0f9a1126db994e527733aa740

Author: Philippe Gerum <r...@xenomai.org>
Date:   Mon Sep  1 12:02:02 2014 +0200

boilerplate: allow reinit upon fork()

---

 lib/boilerplate/ancillaries.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/boilerplate/ancillaries.c b/lib/boilerplate/ancillaries.c
index 5b1f69d..d43a414 100644
--- a/lib/boilerplate/ancillaries.c
+++ b/lib/boilerplate/ancillaries.c
@@ -267,16 +267,23 @@ pid_t get_thread_pid(void)
        return syscall(__NR_gettid);
 }
 
+static pthread_once_t init_once = PTHREAD_ONCE_INIT;
+
+static void reset_on_fork(void)
+{
+       init_once = PTHREAD_ONCE_INIT;
+}
+
 static void __boilerplate_init(void)
 {
+       pthread_atfork(NULL, NULL, reset_on_fork);
        __RT(clock_gettime(CLOCK_MONOTONIC, &__init_date));
        __RT(pthread_mutex_init(&__printlock, NULL));
 }
 
 void boilerplate_init(void)
 {
-       static pthread_once_t once = PTHREAD_ONCE_INIT;
-       pthread_once(&once, __boilerplate_init);
+       pthread_once(&init_once, __boilerplate_init);
 }
 
 const char *config_strings[] = {


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://www.xenomai.org/mailman/listinfo/xenomai-git

Reply via email to