Browse Source

remove __lock dependency from exit

there's no sense in using a powerful lock in exit, because it will
never be unlocked. a thread that arrives at exit while exit is already
in progress just needs to hang forever. use the pause syscall for this
because it's cheap and easy and universally available.
Rich Felker 13 years ago
parent
commit
47c2a22fd6
1 changed files with 4 additions and 2 deletions
  1. 4 2
      src/exit/exit.c

+ 4 - 2
src/exit/exit.c

@@ -2,6 +2,8 @@
 #include <unistd.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <stdio.h>
 #include "libc.h"
 #include "libc.h"
+#include "atomic.h"
+#include "syscall.h"
 
 
 static void dummy()
 static void dummy()
 {
 {
@@ -13,10 +15,10 @@ weak_alias(dummy, __fflush_on_exit);
 
 
 void exit(int code)
 void exit(int code)
 {
 {
-	static int lock[2];
+	static int lock;
 
 
 	/* If more than one thread calls exit, hang until _Exit ends it all */
 	/* If more than one thread calls exit, hang until _Exit ends it all */
-	LOCK(lock);
+	while (a_swap(&lock, 1)) __syscall(SYS_pause);
 
 
 	/* Only do atexit & stdio flush if they were actually used */
 	/* Only do atexit & stdio flush if they were actually used */
 	__funcs_on_exit();
 	__funcs_on_exit();