Fix boolean_t/B_FALSE/B_TRUE compilation issue
[kopensolaris-gnu/glibc.git] / stdlib / cxa_finalize.c
index 4f6f71c..148d57f 100644 (file)
@@ -31,6 +31,7 @@ __cxa_finalize (void *d)
 {
   struct exit_function_list *funcs;
 
+ restart:
   for (funcs = __exit_funcs; funcs; funcs = funcs->next)
     {
       struct exit_function *f;
@@ -44,13 +45,20 @@ __cxa_finalize (void *d)
              /* We don't want to run this cleanup more than once.  */
              && (cxafn = f->func.cxa.fn,
                  cxaarg = f->func.cxa.arg,
-                 ! atomic_compare_and_exchange_bool_acq (&f->flavor, ef_free,
-                                                         ef_cxa)))
+                 ! catomic_compare_and_exchange_bool_acq (&f->flavor, ef_free,
+                                                          ef_cxa)))
            {
+             uint64_t check = __new_exitfn_called;
+
 #ifdef PTR_DEMANGLE
              PTR_DEMANGLE (cxafn);
 #endif
              cxafn (cxaarg, 0);
+
+             /* It is possible that that last exit function registered
+                more exit functions.  Start the loop over.  */
+             if (__builtin_expect (check != __new_exitfn_called, 0))
+               goto restart;
            }
        }
     }