2 Permission is granted to use, modify, and / or redistribute at will.
4 This includes removing authorship notices, re-use of code parts in
5 other software (with or without giving credit), and / or creating a
6 commercial product based on it.
8 This permission is not revocable by the author.
10 This software is provided as-is. Use it at your own risk. There is
11 no warranty whatsoever, neither expressed nor implied, and by using
12 this software you accept that the author(s) shall not be held liable
13 for any loss of data, loss of service, or other damages, be they
14 incidental or consequential. Your only option other than accepting
15 this is not to use the software at all.
17 #ifndef _LIGHTLIBCPP_CPP03_STRICT
22 #include <cstddef> // std::size_t
23 #include <exception> // std::terminate
30 #define _LIGHTLIBCPP_QUICK_EXIT_ARRAY_SIZE 32
37 typedef void (*quick_exit_function_t
)(void);
42 * file-local variables
44 static bool quick_exit_in_progress
= false;
45 static quick_exit_function_t quick_exit_functions
[_LIGHTLIBCPP_QUICK_EXIT_ARRAY_SIZE
];
46 static std::size_t quick_exit_functions_index
= 0;
54 int std::at_quick_exit(quick_exit_function_t f
)
56 // TODO: Ensure thread-safety
58 // Are currently in quick_exit?
59 if (quick_exit_in_progress
)
61 // Call the function directly now
66 // Do we have enough space in the array
67 if (quick_exit_functions_index
== _LIGHTLIBCPP_QUICK_EXIT_ARRAY_SIZE
)
70 // Save the function pointer
71 quick_exit_functions
[quick_exit_functions_index
++] = f
;
77 void std::quick_exit(int status
)
79 // TODO: Ensure thread-safety
81 quick_exit_in_progress
= true;
83 for (;quick_exit_functions_index
> 0;--quick_exit_functions_index
)
85 #ifndef _LIGHTLIBCPP_NO_EXCEPTIONS
90 quick_exit_functions
[quick_exit_functions_index
- 1]();
92 #ifndef _LIGHTLIBCPP_NO_EXCEPTIONS