00db10
Note: The __pthread_once definition in the new unified implementation in
00db10
this patch has been edited. The original version of the patch had an old
00db10
style declaration that was causing a -Werror=old-style-definition failure.
00db10
00db10
commit 36875b06e0ed7f137190b9228bef553adfc338ba
00db10
Author: Torvald Riegel <triegel@redhat.com>
00db10
Date:   Wed May 8 16:35:10 2013 +0200
00db10
00db10
    Fixed and unified pthread_once.
00db10
    
00db10
    [BZ #15215] This unifies various pthread_once architecture-specific
00db10
    implementations which were using the same algorithm with slightly different
00db10
    implementations.  It also adds missing memory barriers that are required for
00db10
    correctness.
00db10
00db10
diff --git a/nptl/sysdeps/unix/sysv/linux/pthread_once.c b/nptl/sysdeps/unix/sysv/linux/pthread_once.c
00db10
new file mode 100644
00db10
index 0000000000000000..2684b660958361d4
00db10
--- /dev/null
00db10
+++ b/nptl/sysdeps/unix/sysv/linux/pthread_once.c
00db10
@@ -0,0 +1,129 @@
00db10
+/* Copyright (C) 2003-2014 Free Software Foundation, Inc.
00db10
+   This file is part of the GNU C Library.
00db10
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
00db10
+
00db10
+   The GNU C Library is free software; you can redistribute it and/or
00db10
+   modify it under the terms of the GNU Lesser General Public
00db10
+   License as published by the Free Software Foundation; either
00db10
+   version 2.1 of the License, or (at your option) any later version.
00db10
+
00db10
+   The GNU C Library is distributed in the hope that it will be useful,
00db10
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
00db10
+   Lesser General Public License for more details.
00db10
+
00db10
+   You should have received a copy of the GNU Lesser General Public
00db10
+   License along with the GNU C Library; if not, see
00db10
+   <http://www.gnu.org/licenses/>.  */
00db10
+
00db10
+#include "pthreadP.h"
00db10
+#include <lowlevellock.h>
00db10
+#include <atomic.h>
00db10
+
00db10
+
00db10
+unsigned long int __fork_generation attribute_hidden;
00db10
+
00db10
+
00db10
+static void
00db10
+clear_once_control (void *arg)
00db10
+{
00db10
+  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
+
00db10
+  /* Reset to the uninitialized state here.  We don't need a stronger memory
00db10
+     order because we do not need to make any other of our writes visible to
00db10
+     other threads that see this value: This function will be called if we
00db10
+     get interrupted (see __pthread_once), so all we need to relay to other
00db10
+     threads is the state being reset again.  */
00db10
+  *once_control = 0;
00db10
+  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
+}
00db10
+
00db10
+
00db10
+/* This is similar to a lock implementation, but we distinguish between three
00db10
+   states: not yet initialized (0), initialization finished (2), and
00db10
+   initialization in progress (__fork_generation | 1).  If in the first state,
00db10
+   threads will try to run the initialization by moving to the second state;
00db10
+   the first thread to do so via a CAS on once_control runs init_routine,
00db10
+   other threads block.
00db10
+   When forking the process, some threads can be interrupted during the second
00db10
+   state; they won't be present in the forked child, so we need to restart
00db10
+   initialization in the child.  To distinguish an in-progress initialization
00db10
+   from an interrupted initialization (in which case we need to reclaim the
00db10
+   lock), we look at the fork generation that's part of the second state: We
00db10
+   can reclaim iff it differs from the current fork generation.
00db10
+   XXX: This algorithm has an ABA issue on the fork generation: If an
00db10
+   initialization is interrupted, we then fork 2^30 times (30 bits of
00db10
+   once_control are used for the fork generation), and try to initialize
00db10
+   again, we can deadlock because we can't distinguish the in-progress and
00db10
+   interrupted cases anymore.  */
00db10
+int
00db10
+__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
00db10
+{
00db10
+  while (1)
00db10
+    {
00db10
+      int oldval, val, newval;
00db10
+
00db10
+      /* We need acquire memory order for this load because if the value
00db10
+         signals that initialization has finished, we need to be see any
00db10
+         data modifications done during initialization.  */
00db10
+      val = *once_control;
00db10
+      atomic_read_barrier();
00db10
+      do
00db10
+	{
00db10
+	  /* Check if the initialization has already been done.  */
00db10
+	  if (__glibc_likely ((val & 2) != 0))
00db10
+	    return 0;
00db10
+
00db10
+	  oldval = val;
00db10
+	  /* We try to set the state to in-progress and having the current
00db10
+	     fork generation.  We don't need atomic accesses for the fork
00db10
+	     generation because it's immutable in a particular process, and
00db10
+	     forked child processes start with a single thread that modified
00db10
+	     the generation.  */
00db10
+	  newval = __fork_generation | 1;
00db10
+	  /* We need acquire memory order here for the same reason as for the
00db10
+	     load from once_control above.  */
00db10
+	  val = atomic_compare_and_exchange_val_acq (once_control, newval,
00db10
+						     oldval);
00db10
+	}
00db10
+      while (__glibc_unlikely (val != oldval));
00db10
+
00db10
+      /* Check if another thread already runs the initializer.	*/
00db10
+      if ((oldval & 1) != 0)
00db10
+	{
00db10
+	  /* Check whether the initializer execution was interrupted by a
00db10
+	     fork.  We know that for both values, bit 0 is set and bit 1 is
00db10
+	     not.  */
00db10
+	  if (oldval == newval)
00db10
+	    {
00db10
+	      /* Same generation, some other thread was faster. Wait.  */
00db10
+	      lll_futex_wait (once_control, newval, LLL_PRIVATE);
00db10
+	      continue;
00db10
+	    }
00db10
+	}
00db10
+
00db10
+      /* This thread is the first here.  Do the initialization.
00db10
+	 Register a cleanup handler so that in case the thread gets
00db10
+	 interrupted the initialization can be restarted.  */
00db10
+      pthread_cleanup_push (clear_once_control, once_control);
00db10
+
00db10
+      init_routine ();
00db10
+
00db10
+      pthread_cleanup_pop (0);
00db10
+
00db10
+
00db10
+      /* Mark *once_control as having finished the initialization.  We need
00db10
+         release memory order here because we need to synchronize with other
00db10
+         threads that want to use the initialized data.  */
00db10
+      atomic_write_barrier();
00db10
+      *once_control = 2;
00db10
+
00db10
+      /* Wake up all other threads.  */
00db10
+      lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
+      break;
00db10
+    }
00db10
+
00db10
+  return 0;
00db10
+}
00db10
+weak_alias (__pthread_once, pthread_once)
00db10
+hidden_def (__pthread_once)
00db10
diff --git a/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c b/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c
00db10
deleted file mode 100644
00db10
index a2111756374174f2..0000000000000000
00db10
--- a/nptl/sysdeps/unix/sysv/linux/sparc/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,93 +0,0 @@
00db10
-/* Copyright (C) 2003-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library; if not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include "pthreadP.h"
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-
00db10
-int
00db10
-__pthread_once (once_control, init_routine)
00db10
-     pthread_once_t *once_control;
00db10
-     void (*init_routine) (void);
00db10
-{
00db10
-  while (1)
00db10
-    {
00db10
-      int oldval, val, newval;
00db10
-
00db10
-      val = *once_control;
00db10
-      do
00db10
-	{
00db10
-	  /* Check if the initialized has already been done.  */
00db10
-	  if ((val & 2) != 0)
00db10
-	    return 0;
00db10
-
00db10
-	  oldval = val;
00db10
-	  newval = (oldval & 3) | __fork_generation | 1;
00db10
-	  val = atomic_compare_and_exchange_val_acq (once_control, newval,
00db10
-						     oldval);
00db10
-	}
00db10
-      while (__builtin_expect (val != oldval, 0));
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) != 0)
00db10
-	{
00db10
-	  /* Check whether the initializer execution was interrupted
00db10
-	     by a fork.	 */
00db10
-	  if (((oldval ^ newval) & -4) == 0)
00db10
-	    {
00db10
-	      /* Same generation, some other thread was faster. Wait.  */
00db10
-	      lll_futex_wait (once_control, newval, LLL_PRIVATE);
00db10
-	      continue;
00db10
-	    }
00db10
-	}
00db10
-
00db10
-      /* This thread is the first here.  Do the initialization.
00db10
-	 Register a cleanup handler so that in case the thread gets
00db10
-	 interrupted the initialization can be restarted.  */
00db10
-      pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-      init_routine ();
00db10
-
00db10
-      pthread_cleanup_pop (0);
00db10
-
00db10
-
00db10
-      /* Add one to *once_control.  */
00db10
-      atomic_increment (once_control);
00db10
-
00db10
-      /* Wake up all other threads.  */
00db10
-      lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-      break;
00db10
-    }
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)
00db10
diff --git a/sysdeps/unix/sysv/linux/aarch64/nptl/pthread_once.c b/sysdeps/unix/sysv/linux/aarch64/nptl/pthread_once.c
00db10
deleted file mode 100644
00db10
index 0897e1e004ef3278..0000000000000000
00db10
--- a/sysdeps/unix/sysv/linux/aarch64/nptl/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,90 +0,0 @@
00db10
-/* Copyright (C) 2004-2012 Free Software Foundation, Inc.
00db10
-
00db10
-   This file is part of the GNU C Library.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public License as
00db10
-   published by the Free Software Foundation; either version 2.1 of the
00db10
-   License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library; if not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include "pthreadP.h"
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-int
00db10
-__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
00db10
-{
00db10
-  for (;;)
00db10
-    {
00db10
-      int oldval;
00db10
-      int newval;
00db10
-
00db10
-      /* Pseudo code:
00db10
-	 newval = __fork_generation | 1;
00db10
-	 oldval = *once_control;
00db10
-	 if ((oldval & 2) == 0)
00db10
-	   *once_control = newval;
00db10
-	 Do this atomically.
00db10
-      */
00db10
-      do
00db10
-	{
00db10
-	  newval = __fork_generation | 1;
00db10
-	  oldval = *once_control;
00db10
-	  if (oldval & 2)
00db10
-	    break;
00db10
-	} while (atomic_compare_and_exchange_val_acq (once_control, newval, oldval) != oldval);
00db10
-
00db10
-      /* Check if the initializer has already been done.  */
00db10
-      if ((oldval & 2) != 0)
00db10
-	return 0;
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) == 0)
00db10
-	break;
00db10
-
00db10
-      /* Check whether the initializer execution was interrupted by a fork.  */
00db10
-      if (oldval != newval)
00db10
-	break;
00db10
-
00db10
-      /* Same generation, some other thread was faster. Wait.  */
00db10
-      lll_futex_wait (once_control, oldval, LLL_PRIVATE);
00db10
-    }
00db10
-
00db10
-  /* This thread is the first here.  Do the initialization.
00db10
-     Register a cleanup handler so that in case the thread gets
00db10
-     interrupted the initialization can be restarted.  */
00db10
-  pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-  init_routine ();
00db10
-
00db10
-  pthread_cleanup_pop (0);
00db10
-
00db10
-  /* Say that the initialisation is done.  */
00db10
-  *once_control = __fork_generation | 2;
00db10
-
00db10
-  /* Wake up all other threads.  */
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)
00db10
diff --git a/sysdeps/unix/sysv/linux/arm/nptl/pthread_once.c b/sysdeps/unix/sysv/linux/arm/nptl/pthread_once.c
00db10
deleted file mode 100644
00db10
index 0c03f1c816a2fad5..0000000000000000
00db10
--- a/sysdeps/unix/sysv/linux/arm/nptl/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,89 +0,0 @@
00db10
-/* Copyright (C) 2004-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library.  If not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include "pthreadP.h"
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-int
00db10
-__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
00db10
-{
00db10
-  for (;;)
00db10
-    {
00db10
-      int oldval;
00db10
-      int newval;
00db10
-
00db10
-      /* Pseudo code:
00db10
-	 newval = __fork_generation | 1;
00db10
-	 oldval = *once_control;
00db10
-	 if ((oldval & 2) == 0)
00db10
-	   *once_control = newval;
00db10
-	 Do this atomically.
00db10
-      */
00db10
-      do
00db10
-	{
00db10
-	  newval = __fork_generation | 1;
00db10
-	  oldval = *once_control;
00db10
-	  if (oldval & 2)
00db10
-	    break;
00db10
-	} while (atomic_compare_and_exchange_val_acq (once_control, newval, oldval) != oldval);
00db10
-
00db10
-      /* Check if the initializer has already been done.  */
00db10
-      if ((oldval & 2) != 0)
00db10
-	return 0;
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) == 0)
00db10
-	break;
00db10
-
00db10
-      /* Check whether the initializer execution was interrupted by a fork.  */
00db10
-      if (oldval != newval)
00db10
-	break;
00db10
-
00db10
-      /* Same generation, some other thread was faster. Wait.  */
00db10
-      lll_futex_wait (once_control, oldval, LLL_PRIVATE);
00db10
-    }
00db10
-
00db10
-  /* This thread is the first here.  Do the initialization.
00db10
-     Register a cleanup handler so that in case the thread gets
00db10
-     interrupted the initialization can be restarted.  */
00db10
-  pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-  init_routine ();
00db10
-
00db10
-  pthread_cleanup_pop (0);
00db10
-
00db10
-  /* Say that the initialisation is done.  */
00db10
-  *once_control = __fork_generation | 2;
00db10
-
00db10
-  /* Wake up all other threads.  */
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)
00db10
diff --git a/sysdeps/unix/sysv/linux/ia64/nptl/pthread_once.c b/sysdeps/unix/sysv/linux/ia64/nptl/pthread_once.c
00db10
deleted file mode 100644
00db10
index 7730935dfec85ae6..0000000000000000
00db10
--- a/sysdeps/unix/sysv/linux/ia64/nptl/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,93 +0,0 @@
00db10
-/* Copyright (C) 2003, 2004, 2007 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library; if not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include "pthreadP.h"
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-
00db10
-int
00db10
-__pthread_once (once_control, init_routine)
00db10
-     pthread_once_t *once_control;
00db10
-     void (*init_routine) (void);
00db10
-{
00db10
-  while (1)
00db10
-    {
00db10
-      int oldval, val, newval;
00db10
-
00db10
-      val = *once_control;
00db10
-      do
00db10
-	{
00db10
-	  /* Check if the initialized has already been done.  */
00db10
-	  if ((val & 2) != 0)
00db10
-	    return 0;
00db10
-
00db10
-	  oldval = val;
00db10
-	  newval = (oldval & 3) | __fork_generation | 1;
00db10
-	  val = atomic_compare_and_exchange_val_acq (once_control, newval,
00db10
-						     oldval);
00db10
-	}
00db10
-      while (__builtin_expect (val != oldval, 0));
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) != 0)
00db10
-	{
00db10
-	  /* Check whether the initializer execution was interrupted
00db10
-	     by a fork.	 */
00db10
-	  if (((oldval ^ newval) & -4) == 0)
00db10
-	    {
00db10
-	      /* Same generation, some other thread was faster. Wait.  */
00db10
-	      lll_futex_wait (once_control, newval, LLL_PRIVATE);
00db10
-	      continue;
00db10
-	    }
00db10
-	}
00db10
-
00db10
-      /* This thread is the first here.  Do the initialization.
00db10
-	 Register a cleanup handler so that in case the thread gets
00db10
-	 interrupted the initialization can be restarted.  */
00db10
-      pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-      init_routine ();
00db10
-
00db10
-      pthread_cleanup_pop (0);
00db10
-
00db10
-
00db10
-      /* Add one to *once_control.  */
00db10
-      atomic_increment (once_control);
00db10
-
00db10
-      /* Wake up all other threads.  */
00db10
-      lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-      break;
00db10
-    }
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)
00db10
diff --git a/sysdeps/unix/sysv/linux/m68k/nptl/pthread_once.c b/sysdeps/unix/sysv/linux/m68k/nptl/pthread_once.c
00db10
deleted file mode 100644
00db10
index 8d81db602eee601f..0000000000000000
00db10
--- a/sysdeps/unix/sysv/linux/m68k/nptl/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,90 +0,0 @@
00db10
-/* Copyright (C) 2010-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Maxim Kuvyrkov <maxim@codesourcery.com>, 2010.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library.  If not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include "pthreadP.h"
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-int
00db10
-__pthread_once (pthread_once_t *once_control, void (*init_routine) (void))
00db10
-{
00db10
-  for (;;)
00db10
-    {
00db10
-      int oldval;
00db10
-      int newval;
00db10
-
00db10
-      /* Pseudo code:
00db10
-	 newval = __fork_generation | 1;
00db10
-	 oldval = *once_control;
00db10
-	 if ((oldval & 2) == 0)
00db10
-	   *once_control = newval;
00db10
-	 Do this atomically.
00db10
-      */
00db10
-      do
00db10
-	{
00db10
-	  newval = __fork_generation | 1;
00db10
-	  oldval = *once_control;
00db10
-	  if (oldval & 2)
00db10
-	    break;
00db10
-	} while (atomic_compare_and_exchange_val_acq (once_control, newval, oldval) != oldval);
00db10
-
00db10
-      /* Check if the initializer has already been done.  */
00db10
-      if ((oldval & 2) != 0)
00db10
-	return 0;
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) == 0)
00db10
-	break;
00db10
-
00db10
-      /* Check whether the initializer execution was interrupted by a fork.  */
00db10
-      if (oldval != newval)
00db10
-	break;
00db10
-
00db10
-      /* Same generation, some other thread was faster. Wait.  */
00db10
-      lll_futex_wait (once_control, oldval, LLL_PRIVATE);
00db10
-    }
00db10
-
00db10
-  /* This thread is the first here.  Do the initialization.
00db10
-     Register a cleanup handler so that in case the thread gets
00db10
-     interrupted the initialization can be restarted.  */
00db10
-  pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-  init_routine ();
00db10
-
00db10
-  pthread_cleanup_pop (0);
00db10
-
00db10
-  /* Say that the initialisation is done.  */
00db10
-  *once_control = __fork_generation | 2;
00db10
-
00db10
-  /* Wake up all other threads.  */
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)
00db10
diff --git a/sysdeps/unix/sysv/linux/mips/nptl/pthread_once.c b/sysdeps/unix/sysv/linux/mips/nptl/pthread_once.c
00db10
deleted file mode 100644
00db10
index 308da8bbce0c3800..0000000000000000
00db10
--- a/sysdeps/unix/sysv/linux/mips/nptl/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,93 +0,0 @@
00db10
-/* Copyright (C) 2003-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library.  If not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include "pthreadP.h"
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-
00db10
-int
00db10
-__pthread_once (once_control, init_routine)
00db10
-     pthread_once_t *once_control;
00db10
-     void (*init_routine) (void);
00db10
-{
00db10
-  while (1)
00db10
-    {
00db10
-      int oldval, val, newval;
00db10
-
00db10
-      val = *once_control;
00db10
-      do
00db10
-	{
00db10
-	  /* Check if the initialized has already been done.  */
00db10
-	  if ((val & 2) != 0)
00db10
-	    return 0;
00db10
-
00db10
-	  oldval = val;
00db10
-	  newval = (oldval & 3) | __fork_generation | 1;
00db10
-	  val = atomic_compare_and_exchange_val_acq (once_control, newval,
00db10
-						     oldval);
00db10
-	}
00db10
-      while (__builtin_expect (val != oldval, 0));
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) != 0)
00db10
-	{
00db10
-	  /* Check whether the initializer execution was interrupted
00db10
-	     by a fork.	 */
00db10
-	  if (((oldval ^ newval) & -4) == 0)
00db10
-	    {
00db10
-	      /* Same generation, some other thread was faster. Wait.  */
00db10
-	      lll_futex_wait (once_control, newval, LLL_PRIVATE);
00db10
-	      continue;
00db10
-	    }
00db10
-	}
00db10
-
00db10
-      /* This thread is the first here.  Do the initialization.
00db10
-	 Register a cleanup handler so that in case the thread gets
00db10
-	 interrupted the initialization can be restarted.  */
00db10
-      pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-      init_routine ();
00db10
-
00db10
-      pthread_cleanup_pop (0);
00db10
-
00db10
-
00db10
-      /* Add one to *once_control.  */
00db10
-      atomic_increment (once_control);
00db10
-
00db10
-      /* Wake up all other threads.  */
00db10
-      lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-      break;
00db10
-    }
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)
00db10
diff --git a/sysdeps/unix/sysv/linux/tile/nptl/pthread_once.c b/sysdeps/unix/sysv/linux/tile/nptl/pthread_once.c
00db10
deleted file mode 100644
00db10
index 93ac29b24c440b2c..0000000000000000
00db10
--- a/sysdeps/unix/sysv/linux/tile/nptl/pthread_once.c
00db10
+++ /dev/null
00db10
@@ -1,94 +0,0 @@
00db10
-/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
00db10
-   This file is part of the GNU C Library.
00db10
-   Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
00db10
-   Based on work contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
00db10
-
00db10
-   The GNU C Library is free software; you can redistribute it and/or
00db10
-   modify it under the terms of the GNU Lesser General Public
00db10
-   License as published by the Free Software Foundation; either
00db10
-   version 2.1 of the License, or (at your option) any later version.
00db10
-
00db10
-   The GNU C Library is distributed in the hope that it will be useful,
00db10
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
00db10
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00db10
-   Lesser General Public License for more details.
00db10
-
00db10
-   You should have received a copy of the GNU Lesser General Public
00db10
-   License along with the GNU C Library.  If not, see
00db10
-   <http://www.gnu.org/licenses/>.  */
00db10
-
00db10
-#include <nptl/pthreadP.h>
00db10
-#include <lowlevellock.h>
00db10
-
00db10
-
00db10
-unsigned long int __fork_generation attribute_hidden;
00db10
-
00db10
-
00db10
-static void
00db10
-clear_once_control (void *arg)
00db10
-{
00db10
-  pthread_once_t *once_control = (pthread_once_t *) arg;
00db10
-
00db10
-  *once_control = 0;
00db10
-  lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-}
00db10
-
00db10
-
00db10
-int
00db10
-__pthread_once (once_control, init_routine)
00db10
-     pthread_once_t *once_control;
00db10
-     void (*init_routine) (void);
00db10
-{
00db10
-  while (1)
00db10
-    {
00db10
-      int oldval, val, newval;
00db10
-
00db10
-      val = *once_control;
00db10
-      do
00db10
-	{
00db10
-	  /* Check if the initialized has already been done.  */
00db10
-	  if ((val & 2) != 0)
00db10
-	    return 0;
00db10
-
00db10
-	  oldval = val;
00db10
-	  newval = (oldval & 3) | __fork_generation | 1;
00db10
-	  val = atomic_compare_and_exchange_val_acq (once_control, newval,
00db10
-						     oldval);
00db10
-	}
00db10
-      while (__builtin_expect (val != oldval, 0));
00db10
-
00db10
-      /* Check if another thread already runs the initializer.	*/
00db10
-      if ((oldval & 1) != 0)
00db10
-	{
00db10
-	  /* Check whether the initializer execution was interrupted
00db10
-	     by a fork.	 */
00db10
-	  if (((oldval ^ newval) & -4) == 0)
00db10
-	    {
00db10
-	      /* Same generation, some other thread was faster. Wait.  */
00db10
-	      lll_futex_wait (once_control, newval, LLL_PRIVATE);
00db10
-	      continue;
00db10
-	    }
00db10
-	}
00db10
-
00db10
-      /* This thread is the first here.  Do the initialization.
00db10
-	 Register a cleanup handler so that in case the thread gets
00db10
-	 interrupted the initialization can be restarted.  */
00db10
-      pthread_cleanup_push (clear_once_control, once_control);
00db10
-
00db10
-      init_routine ();
00db10
-
00db10
-      pthread_cleanup_pop (0);
00db10
-
00db10
-
00db10
-      /* Add one to *once_control.  */
00db10
-      atomic_increment (once_control);
00db10
-
00db10
-      /* Wake up all other threads.  */
00db10
-      lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
00db10
-      break;
00db10
-    }
00db10
-
00db10
-  return 0;
00db10
-}
00db10
-weak_alias (__pthread_once, pthread_once)
00db10
-hidden_def (__pthread_once)