[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

r5696 - in glibc-package/trunk/debian: . patches patches/hurd-i386



Author: sthibault
Date: 2013-09-21 21:34:08 +0000 (Sat, 21 Sep 2013)
New Revision: 5696

Added:
   glibc-package/trunk/debian/patches/hurd-i386/cvs-pthread_atfork.diff
   glibc-package/trunk/debian/patches/hurd-i386/tg-pthread-atfork.diff
Modified:
   glibc-package/trunk/debian/changelog
   glibc-package/trunk/debian/patches/series
Log:
  * patches/hurd-i386/tg-pthread-atfork.diff,cvs-pthread_atfork.diff: Add
    pthread_atfork support.


Modified: glibc-package/trunk/debian/changelog
===================================================================
--- glibc-package/trunk/debian/changelog	2013-09-21 13:56:21 UTC (rev 5695)
+++ glibc-package/trunk/debian/changelog	2013-09-21 21:34:08 UTC (rev 5696)
@@ -17,6 +17,8 @@
     Winter to fix hurd-i386's _PATH_MOUNTED according to Debian usage.
   * patches/hurd-i386/tg-socket{,pair}_flags.diff: New patch from Thomas
     Schwinge to add support for SOCK_CLOEXEC and SOCK_NONBLOCK.
+  * patches/hurd-i386/tg-pthread-atfork.diff,cvs-pthread_atfork.diff: Add
+    pthread_atfork support.
 
  -- Adam Conrad <adconrad@0c3.net>  Thu, 01 Aug 2013 23:00:51 +0100
 

Added: glibc-package/trunk/debian/patches/hurd-i386/cvs-pthread_atfork.diff
===================================================================
--- glibc-package/trunk/debian/patches/hurd-i386/cvs-pthread_atfork.diff	                        (rev 0)
+++ glibc-package/trunk/debian/patches/hurd-i386/cvs-pthread_atfork.diff	2013-09-21 21:34:08 UTC (rev 5696)
@@ -0,0 +1,147 @@
+This adds support for pthread_atfork.
+
+---
+ libpthread/Versions                    |    1 
+ libpthread/forward.c                   |  105 ++++++++++++++++++++++++++++++++++++++++++++
+ libpthread/sysdeps/generic/pt-atfork.c |    2 
+ 3 files changed, 107 insertions(+), 1 deletion(-)
+
+--- a/libpthread/Versions
++++ b/libpthread/Versions
+@@ -18,6 +18,7 @@ libc {
+     __pthread_get_cleanup_stack;
+   GLIBC_PRIVATE {
+     __libc_pthread_init;
++    __register_atfork;
+   }
+ }
+ 
+--- a/libpthread/forward.c
++++ b/libpthread/forward.c
+@@ -17,6 +17,7 @@
+    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+    02111-1307 USA.  */
+ 
++#include <errno.h>
+ #include <dlfcn.h>
+ #include <stdlib.h>
+ #include <shlib-compat.h>
+@@ -125,3 +126,107 @@ FORWARD (pthread_setcanceltype, (int type, int *oldtype), (type, oldtype), 0)
+ 
+ struct __pthread_cancelation_handler *dummy_list;
+ FORWARD2 (__pthread_get_cleanup_stack, struct __pthread_cancelation_handler **, (void), (), return &dummy_list);
++
++
++/* Fork interaction */
++
++struct atfork {
++  void (*prepare) (void);
++  void (*parent) (void);
++  void (*child) (void);
++  struct atfork *prev;
++  struct atfork *next;
++};
++
++/* TODO: better locking */
++static struct mutex atfork_lock;
++static struct atfork *fork_handlers, *fork_last_handler;
++
++static void
++atfork_pthread_prepare (void)
++{
++  struct atfork *handlers, *last_handler;
++
++  __mutex_lock (&atfork_lock);
++  handlers = fork_handlers;
++  last_handler = fork_last_handler;
++  __mutex_unlock (&atfork_lock);
++
++  if (!last_handler)
++    return;
++
++  while(1)
++  {
++    if (last_handler->prepare != NULL)
++      last_handler->prepare ();
++    if (last_handler == handlers)
++      break;
++    last_handler = last_handler->prev;
++  }
++}
++text_set_element (_hurd_atfork_prepare_hook, atfork_pthread_prepare);
++
++static void
++atfork_pthread_parent (void)
++{
++  struct atfork *handlers;
++
++  __mutex_lock (&atfork_lock);
++  handlers = fork_handlers;
++  __mutex_unlock (&atfork_lock);
++
++  while (handlers)
++  {
++    if (handlers->parent != NULL)
++      handlers->parent ();
++    handlers = handlers->next;
++  }
++}
++text_set_element (_hurd_atfork_parent_hook, atfork_pthread_parent);
++
++static void
++atfork_pthread_child (void)
++{
++  struct atfork *handlers;
++
++  __mutex_lock (&atfork_lock);
++  handlers = fork_handlers;
++  __mutex_unlock (&atfork_lock);
++
++  while (handlers)
++  {
++    if (handlers->child != NULL)
++      handlers->child ();
++    handlers = handlers->next;
++  }
++}
++text_set_element (_hurd_atfork_child_hook, atfork_pthread_child);
++
++int
++__register_atfork (
++    void (*prepare) (void),
++    void (*parent) (void),
++    void (*child) (void))
++{
++  struct atfork *new = malloc (sizeof (*new));
++  if (!new)
++    return errno;
++
++  new->prepare = prepare;
++  new->parent = parent;
++  new->child = child;
++  new->prev = NULL;
++
++  __mutex_lock (&atfork_lock);
++  new->next = fork_handlers;
++  if (fork_handlers)
++  	fork_handlers->prev = new;
++  fork_handlers = new;
++  if (!fork_last_handler)
++    fork_last_handler = new;
++  __mutex_unlock (&atfork_lock);
++
++  return 0;
++}
++
++/* TODO: unregister_atfork, and define UNREGISTER_ATFORK, for module unload support */
+--- a/libpthread/sysdeps/generic/pt-atfork.c
++++ b/libpthread/sysdeps/generic/pt-atfork.c
+@@ -25,7 +25,7 @@ pthread_atfork (void (*prepare) (void),
+ 		void (*parent) (void),
+ 		void (*child) (void))
+ {
+-  return ENOSYS;
++  return __register_atfork (prepare, parent, child);
+ }
+
+ stub_warning (pthread_atfork)

Added: glibc-package/trunk/debian/patches/hurd-i386/tg-pthread-atfork.diff
===================================================================
--- glibc-package/trunk/debian/patches/hurd-i386/tg-pthread-atfork.diff	                        (rev 0)
+++ glibc-package/trunk/debian/patches/hurd-i386/tg-pthread-atfork.diff	2013-09-21 21:34:08 UTC (rev 5696)
@@ -0,0 +1,60 @@
+From: Samuel Thibault <samuel.thibault@ens-lyon.org>
+Subject: [PATCH] Add fork hooks for pthread_atfork
+
+2013-09-21  Samuel Thibault  <samuel.thibault@ens-lyon.org>
+
+pthread_atfork needs application callbacks to be called outside any locking.
+
+* sysdeps/mach/hurd/fork.c (_hurd_atfork_prepare_hook, _hurd_atfork_child_hook,
+_hurd_atfork_parent_hook): New hooks.
+(__fork): Call _hurd_atfork_prepare_hook hooks before all locking, call
+_hurd_atfork_parent_hook or _hurd_atfork_child_hook after all unlocking.
+
+Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
+
+---
+ sysdeps/mach/hurd/fork.c | 15 +++++++++++++++
+ 1 file changed, 15 insertions(+)
+
+diff --git a/sysdeps/mach/hurd/fork.c b/sysdeps/mach/hurd/fork.c
+index ab11bab..3a6803e 100644
+--- a/sysdeps/mach/hurd/fork.c
++++ b/sysdeps/mach/hurd/fork.c
+@@ -34,6 +34,11 @@
+ symbol_set_declare (_hurd_fork_locks)
+ 
+ 
++/* Application callbacks registered through pthread_atfork.  */
++DEFINE_HOOK (_hurd_atfork_prepare_hook, (void));
++DEFINE_HOOK (_hurd_atfork_child_hook, (void));
++DEFINE_HOOK (_hurd_atfork_parent_hook, (void));
++
+ /* Things that want to be called before we fork, to prepare the parent for
+    task_create, when the new child task will inherit our address space.  */
+ DEFINE_HOOK (_hurd_fork_prepare_hook, (void));
+@@ -62,6 +67,8 @@ __fork (void)
+   error_t err;
+   struct hurd_sigstate *volatile ss;
+ 
++  RUN_HOOK (_hurd_atfork_prepare_hook, ());
++
+   ss = _hurd_self_sigstate ();
+   __spin_lock (&ss->critical_section_lock);
+ 
+@@ -695,6 +702,14 @@ __fork (void)
+ 
+   _hurd_critical_section_unlock (ss);
+ 
++  if (!err)
++    {
++      if (pid)
++	RUN_HOOK (_hurd_atfork_parent_hook, ());
++      else
++	RUN_HOOK (_hurd_atfork_child_hook, ());
++    }
++
+   return err ? __hurd_fail (err) : pid;
+ }
+ libc_hidden_def (__fork)
+-- 
+tg: (9a079e2..) t/pthread-atfork (depends on: baseline)

Modified: glibc-package/trunk/debian/patches/series
===================================================================
--- glibc-package/trunk/debian/patches/series	2013-09-21 13:56:21 UTC (rev 5695)
+++ glibc-package/trunk/debian/patches/series	2013-09-21 21:34:08 UTC (rev 5696)
@@ -130,6 +130,8 @@
 hurd-i386/submitted-path_mounted.diff
 hurd-i386/tg-socket_flags.diff
 hurd-i386/tg-socketpair_flags.diff
+hurd-i386/tg-pthread-atfork.diff
+hurd-i386/cvs-pthread_atfork.diff
 
 i386/local-biarch.diff
 i386/local-cmov.diff


Reply to: