]> git.saurik.com Git - apple/libc.git/blobdiff - stdlib/FreeBSD/atexit.c.patch
Libc-498.tar.gz
[apple/libc.git] / stdlib / FreeBSD / atexit.c.patch
index 1aae327a55bdefcbc27c345a1feb4b4797dde842..1aa7e4240f63f48bf4aeefb3fdaeba78005c35f8 100644 (file)
@@ -1,5 +1,5 @@
---- atexit.c.orig      2004-03-11 13:16:53.000000000 -0800
-+++ atexit.c   2004-09-15 00:14:26.000000000 -0700
+--- atexit.c.orig      2006-04-09 01:23:25.000000000 -0700
++++ atexit.c   2006-04-09 01:44:07.000000000 -0700
 @@ -45,6 +45,9 @@
  #include <stdlib.h>
  #include <unistd.h>
  #include "atexit.h"
  #include "un-namespace.h"
  
-@@ -125,7 +128,11 @@
+@@ -74,6 +77,7 @@
+ };
+ static struct atexit *__atexit;               /* points to head of LIFO stack */
++static int new_registration;
+ /*
+  * Register the function described by 'fptr' to be called at application
+@@ -109,6 +113,7 @@
+               __atexit = p;
+       }
+       p->fns[p->ind++] = *fptr;
++      new_registration = 1;
+       _MUTEX_UNLOCK(&atexit_mutex);
+       return 0;
+ }
+@@ -125,7 +130,11 @@
        fn.fn_type = ATEXIT_FN_STD;
        fn.fn_ptr.std_func = func;;
        fn.fn_arg = NULL;
@@ -22,7 +38,7 @@
  
        error = atexit_register(&fn);   
        return (error);
-@@ -156,7 +163,7 @@
+@@ -156,13 +165,14 @@
   * handlers are called.
   */
  void
  {
        struct atexit *p;
        struct atexit_fn fn;
+       int n;
+       _MUTEX_LOCK(&atexit_mutex);
++restart:
+       for (p = __atexit; p; p = p->next) {
+               for (n = p->ind; --n >= 0;) {
+                       if (p->fns[n].fn_type == ATEXIT_FN_EMPTY)
+@@ -175,6 +185,7 @@
+                         has already been called.
+                       */
+                       p->fns[n].fn_type = ATEXIT_FN_EMPTY;
++                      new_registration = 0;
+                       _MUTEX_UNLOCK(&atexit_mutex);
+               
+                       /* Call the function of correct type. */
+@@ -183,6 +194,8 @@
+                       else if (fn.fn_type == ATEXIT_FN_STD)
+                               fn.fn_ptr.std_func();
+                       _MUTEX_LOCK(&atexit_mutex);
++                      if (new_registration)
++                          goto restart;
+               }
+       }
+       _MUTEX_UNLOCK(&atexit_mutex);