libc: move exits to its own translation unit (another good idea from 9front)

This commit is contained in:
Giacomo Tesio 2017-10-23 00:28:28 +02:00
parent 2a4b3f26d6
commit 9f8050aa4a
3 changed files with 43 additions and 22 deletions

View File

@ -139,6 +139,7 @@
"port/ctype.c",
"port/encodefmt.c",
"port/execl.c",
"port/exits.c",
"port/exp.c",
"port/fabs.c",
"port/floor.c",

View File

@ -10,6 +10,8 @@
#include <u.h>
#include <libc.h>
extern void (*_jehanne_onexit)(void);
#define NEXIT 33
typedef struct Onex Onex;
@ -21,11 +23,26 @@ struct Onex{
static Lock onexlock;
Onex onex[NEXIT];
static void
onexit(void)
{
int i, pid;
void (*f)(void);
pid = jehanne_getpid();
for(i = nelem(onex)-1; i >= 0; i--)
if((f = onex[i].f) != nil && onex[i].pid == pid) {
onex[i].f = nil;
(*f)();
}
}
int
jehanne_atexit(void (*f)(void))
{
int i;
_jehanne_onexit = onexit;
jehanne_lock(&onexlock);
for(i=0; i<NEXIT; i++)
if(onex[i].f == 0) {
@ -48,25 +65,3 @@ jehanne_atexitdont(void (*f)(void))
if(onex[i].f == f && onex[i].pid == pid)
onex[i].f = 0;
}
#pragma profile off
void
jehanne_exits(const char *s)
{
void _fini(void);
int i, pid;
void (*f)(void);
pid = jehanne_getpid();
for(i = NEXIT-1; i >= 0; i--)
if((f = onex[i].f) && pid == onex[i].pid) {
onex[i].f = 0;
(*f)();
}
_fini();
_exits(s);
__builtin_unreachable();
}
#pragma profile on

View File

@ -0,0 +1,25 @@
/*
* This file is part of the UCB release of Plan 9. It is subject to the license
* terms in the LICENSE file found in the top-level directory of this
* distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
* part of the UCB release of Plan 9, including this file, may be copied,
* modified, propagated, or distributed except according to the terms contained
* in the LICENSE file.
*/
#include <u.h>
#include <libc.h>
void (*_jehanne_onexit)(void);
void
jehanne_exits(const char *s)
{
void _fini(void);
if(_jehanne_onexit != nil)
(*_jehanne_onexit)();
_fini();
_exits(s);
__builtin_unreachable();
}