mirror of
https://github.com/fluencelabs/musl
synced 2025-06-18 17:31:38 +00:00
add c11 quick_exit and at_quick_exit functions
This commit is contained in:
@ -43,6 +43,8 @@ void abort (void);
|
|||||||
int atexit (void (*) (void));
|
int atexit (void (*) (void));
|
||||||
void exit (int);
|
void exit (int);
|
||||||
void _Exit (int);
|
void _Exit (int);
|
||||||
|
int at_quick_exit (void (*) (void));
|
||||||
|
void quick_exit (int);
|
||||||
|
|
||||||
char *getenv (const char *);
|
char *getenv (const char *);
|
||||||
|
|
||||||
|
29
src/exit/at_quick_exit.c
Normal file
29
src/exit/at_quick_exit.c
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
#define COUNT 32
|
||||||
|
|
||||||
|
static void (*funcs[COUNT])(void);
|
||||||
|
static int count;
|
||||||
|
static int lock[2];
|
||||||
|
|
||||||
|
void __funcs_on_quick_exit()
|
||||||
|
{
|
||||||
|
void (*func)(void);
|
||||||
|
LOCK(lock);
|
||||||
|
while (count > 0) {
|
||||||
|
func = funcs[--count];
|
||||||
|
UNLOCK(lock);
|
||||||
|
func();
|
||||||
|
LOCK(lock);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int at_quick_exit(void (*func)(void))
|
||||||
|
{
|
||||||
|
if (count == 32) return -1;
|
||||||
|
LOCK(lock);
|
||||||
|
funcs[count++] = func;
|
||||||
|
UNLOCK(lock);
|
||||||
|
return 0;
|
||||||
|
}
|
15
src/exit/quick_exit.c
Normal file
15
src/exit/quick_exit.c
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#include <stdlib.h>
|
||||||
|
#include "syscall.h"
|
||||||
|
#include "atomic.h"
|
||||||
|
#include "libc.h"
|
||||||
|
|
||||||
|
static void dummy() { }
|
||||||
|
weak_alias(dummy, __funcs_on_quick_exit);
|
||||||
|
|
||||||
|
void quick_exit(int code)
|
||||||
|
{
|
||||||
|
static int lock;
|
||||||
|
while (a_swap(&lock, 1)) __syscall(SYS_pause);
|
||||||
|
__funcs_on_quick_exit();
|
||||||
|
_Exit(code);
|
||||||
|
}
|
Reference in New Issue
Block a user