am bf397b60: am 21372896: Merge "fix __cxa_finalize() implementation to be thread safe."

* commit 'bf397b601189f8a63c8a842e16af5ed004ef75f5':
  fix __cxa_finalize() implementation to be thread safe.
diff --git a/libc/stdlib/atexit.c b/libc/stdlib/atexit.c
index f4bcab9..55b7132 100644
--- a/libc/stdlib/atexit.c
+++ b/libc/stdlib/atexit.c
@@ -131,6 +131,7 @@
 	if (__atexit_invalid)
 		return;
 
+	_ATEXIT_LOCK();
 	call_depth++;
 
 	for (p = __atexit; p != NULL; p = p->next) {
@@ -149,6 +150,7 @@
 				p->fns[n].fn_ptr.cxa_func = NULL;
 				mprotect(p, pgsize, PROT_READ);
 			}
+			_ATEXIT_UNLOCK();
 #if ANDROID
                         /* it looks like we should always call the function
                          * with an argument, even if dso is not NULL. Otherwise
@@ -162,6 +164,7 @@
 			else
 				(*fn.fn_ptr.std_func)();
 #endif /* !ANDROID */
+			_ATEXIT_LOCK();
 		}
 	}
 
@@ -178,6 +181,7 @@
 		}
 		__atexit = NULL;
 	}
+	_ATEXIT_UNLOCK();
 }
 
 /*