atexit() is now thread-safe.
Now calls _IO_cleanup() instead of __cleanup() to be able to be compiled against glibc stdio as well. Renamed variables to be much nicer. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3148 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -14,21 +14,20 @@
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include <syscalls.h>
|
#include <syscalls.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
|
|
||||||
// ToDo: move this puppy to a more standard location
|
|
||||||
#include "../stdio/local.h"
|
#include "../stdio/local.h"
|
||||||
|
//#include "stdio_private.h"
|
||||||
|
|
||||||
extern void _thread_do_exit_notification(void);
|
extern void _thread_do_exit_notification(void);
|
||||||
|
|
||||||
|
static void (*_gExitStack[ATEXIT_MAX])(void) = {0};
|
||||||
static void (*_Exit_Stack[ATEXIT_MAX])(void) = {0};
|
static int32 _gExitStackIndex = 0;
|
||||||
static int _Exit_SP = 0;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -43,13 +42,13 @@ int
|
|||||||
atexit(void (*func)(void))
|
atexit(void (*func)(void))
|
||||||
{
|
{
|
||||||
// push the function pointer onto the exit stack
|
// push the function pointer onto the exit stack
|
||||||
|
int32 index = atomic_add(&_gExitStackIndex, 1);
|
||||||
if (_Exit_SP < ATEXIT_MAX) {
|
|
||||||
_Exit_Stack[_Exit_SP++] = func;
|
if (index >= ATEXIT_MAX)
|
||||||
return 0;
|
return -1;
|
||||||
}
|
|
||||||
|
_gExitStack[index] = func;
|
||||||
return -1;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -60,12 +59,13 @@ exit(int status)
|
|||||||
_thread_do_exit_notification();
|
_thread_do_exit_notification();
|
||||||
|
|
||||||
// unwind the exit stack, calling the registered functions
|
// unwind the exit stack, calling the registered functions
|
||||||
while (_Exit_SP > 0)
|
while (_gExitStackIndex-- > 0)
|
||||||
(*_Exit_Stack[--_Exit_SP])();
|
(*_gExitStack[_gExitStackIndex])();
|
||||||
|
|
||||||
// close all open files
|
// close all open files
|
||||||
(*__cleanup)();
|
_IO_cleanup();
|
||||||
|
|
||||||
// exit with status code
|
// exit with status code
|
||||||
sys_exit(status);
|
sys_exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user