X-Git-Url: http://nsz.repo.hu/git/?p=musl;a=blobdiff_plain;f=src%2Fexit%2Fexit.c;h=fc2914844959eac78a3f76dccb302ef0d3d8fe25;hp=d0c1bfc1d5b68a08873a367549ad09d4b310ea91;hb=47c2a22fd6adcaf3f27b093df49bd97e3fdc16e7;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01 diff --git a/src/exit/exit.c b/src/exit/exit.c index d0c1bfc1..fc291484 100644 --- a/src/exit/exit.c +++ b/src/exit/exit.c @@ -2,9 +2,14 @@ #include #include #include "libc.h" +#include "atomic.h" +#include "syscall.h" -/* __overflow.c and atexit.c override these */ -static int (*const dummy)() = 0; +static void dummy() +{ +} + +/* __towrite.c and atexit.c override these */ weak_alias(dummy, __funcs_on_exit); weak_alias(dummy, __fflush_on_exit); @@ -13,11 +18,11 @@ void exit(int code) static int lock; /* 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 */ - if (__funcs_on_exit) __funcs_on_exit(); - if (__fflush_on_exit) __fflush_on_exit(0); + __funcs_on_exit(); + __fflush_on_exit(); /* Destructor s**t is kept separate from atexit to avoid bloat */ if (libc.fini) libc.fini();