978e96
commit 63668b7084ac26865136e59fdf17781f9f49bd99
978e96
Author: Torvald Riegel <triegel@redhat.com>
978e96
Date:   Fri Oct 11 18:58:04 2013 +0300
978e96
978e96
    pthread_once: Clean up constants.
978e96
    
978e96
    [BZ #15215] This just gives a name to the integer constants being used.
978e96
978e96
diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h
978e96
index dda1032d5aa95234..1a842e06bff82479 100644
978e96
--- a/nptl/pthreadP.h
978e96
+++ b/nptl/pthreadP.h
978e96
@@ -159,6 +159,12 @@ enum
978e96
 #define FUTEX_TID_MASK		0x3fffffff
978e96
 
978e96
 
978e96
+/* pthread_once definitions.  See __pthread_once for how these are used.  */
978e96
+#define __PTHREAD_ONCE_INPROGRESS	1
978e96
+#define __PTHREAD_ONCE_DONE		2
978e96
+#define __PTHREAD_ONCE_FORK_GEN_INCR	4
978e96
+
978e96
+
978e96
 /* Internal variables.  */
978e96
 
978e96
 
978e96
diff --git a/nptl/pthread_once.c b/nptl/pthread_once.c
978e96
index 10c01d6023508e3c..595bd7e298003e00 100644
978e96
--- a/nptl/pthread_once.c
978e96
+++ b/nptl/pthread_once.c
978e96
@@ -40,8 +40,11 @@ clear_once_control (void *arg)
978e96
 
978e96
 
978e96
 /* This is similar to a lock implementation, but we distinguish between three
978e96
-   states: not yet initialized (0), initialization finished (2), and
978e96
-   initialization in progress (__fork_generation | 1).  If in the first state,
978e96
+   states: not yet initialized (0), initialization in progress
978e96
+   (__fork_generation | __PTHREAD_ONCE_INPROGRESS), and initialization
978e96
+   finished (__PTHREAD_ONCE_DONE); __fork_generation does not use the bits
978e96
+   that are used for __PTHREAD_ONCE_INPROGRESS and __PTHREAD_ONCE_DONE (which
978e96
+   is what __PTHREAD_ONCE_FORK_GEN_INCR is used for).  If in the first state,
978e96
    threads will try to run the initialization by moving to the second state;
978e96
    the first thread to do so via a CAS on once_control runs init_routine,
978e96
    other threads block.
978e96
@@ -66,14 +69,14 @@ __pthread_once (once_control, init_routine)
978e96
       int oldval, val, newval;
978e96
 
978e96
       /* We need acquire memory order for this load because if the value
978e96
-         signals that initialization has finished, we need to be see any
978e96
+         signals that initialization has finished, we need to see any
978e96
          data modifications done during initialization.  */
978e96
       val = *once_control;
978e96
       atomic_read_barrier();
978e96
       do
978e96
 	{
978e96
 	  /* Check if the initialization has already been done.  */
978e96
-	  if (__glibc_likely ((val & 2) != 0))
978e96
+	  if (__glibc_likely ((val & __PTHREAD_ONCE_DONE) != 0))
978e96
 	    return 0;
978e96
 
978e96
 	  oldval = val;
978e96
@@ -82,7 +85,7 @@ __pthread_once (once_control, init_routine)
978e96
 	     generation because it's immutable in a particular process, and
978e96
 	     forked child processes start with a single thread that modified
978e96
 	     the generation.  */
978e96
-	  newval = __fork_generation | 1;
978e96
+	  newval = __fork_generation | __PTHREAD_ONCE_INPROGRESS;
978e96
 	  /* We need acquire memory order here for the same reason as for the
978e96
 	     load from once_control above.  */
978e96
 	  val = atomic_compare_and_exchange_val_acq (once_control, newval,
978e96
@@ -91,11 +94,11 @@ __pthread_once (once_control, init_routine)
978e96
       while (__glibc_unlikely (val != oldval));
978e96
 
978e96
       /* Check if another thread already runs the initializer.	*/
978e96
-      if ((oldval & 1) != 0)
978e96
+      if ((oldval & __PTHREAD_ONCE_INPROGRESS) != 0)
978e96
 	{
978e96
 	  /* Check whether the initializer execution was interrupted by a
978e96
-	     fork.  We know that for both values, bit 0 is set and bit 1 is
978e96
-	     not.  */
978e96
+	     fork.  We know that for both values, __PTHREAD_ONCE_INPROGRESS
978e96
+	     is set and __PTHREAD_ONCE_DONE is not.  */
978e96
 	  if (oldval == newval)
978e96
 	    {
978e96
 	      /* Same generation, some other thread was faster. Wait.  */
978e96
@@ -118,7 +121,7 @@ __pthread_once (once_control, init_routine)
978e96
          release memory order here because we need to synchronize with other
978e96
          threads that want to use the initialized data.  */
978e96
       atomic_write_barrier();
978e96
-      *once_control = 2;
978e96
+      *once_control = __PTHREAD_ONCE_DONE;
978e96
 
978e96
       /* Wake up all other threads.  */
978e96
       lll_futex_wake (once_control, INT_MAX, LLL_PRIVATE);
978e96
diff --git a/nptl/sysdeps/unix/sysv/linux/fork.c b/nptl/sysdeps/unix/sysv/linux/fork.c
978e96
index 0635bfdb6cdf0aa8..8c197cb8e4347959 100644
978e96
--- a/nptl/sysdeps/unix/sysv/linux/fork.c
978e96
+++ b/nptl/sysdeps/unix/sysv/linux/fork.c
978e96
@@ -146,8 +146,9 @@ __libc_fork (void)
978e96
 
978e96
       assert (THREAD_GETMEM (self, tid) != ppid);
978e96
 
978e96
+      /* See __pthread_once.  */
978e96
       if (__fork_generation_pointer != NULL)
978e96
-	*__fork_generation_pointer += 4;
978e96
+	*__fork_generation_pointer += __PTHREAD_ONCE_FORK_GEN_INCR;
978e96
 
978e96
       /* Adjust the PID field for the new process.  */
978e96
       THREAD_SETMEM (self, pid, THREAD_GETMEM (self, tid));