10#include <ascii-chat/common.h>
11#include <ascii-chat/platform/system.h>
12#include <ascii-chat/platform/init.h>
13#include <ascii-chat/platform/memory.h>
14#include <ascii-chat/log/logging.h>
15#include <ascii-chat/buffer_pool.h>
16#include <ascii-chat/video/palette.h>
17#include <ascii-chat/video/simd/common.h>
18#include <ascii-chat/video/webcam/webcam.h>
19#include <ascii-chat/options/colorscheme.h>
20#include <ascii-chat/util/time.h>
21#include <ascii-chat/util/pcre2.h>
22#include <ascii-chat/asciichat_errno.h>
23#include <ascii-chat/crypto/known_hosts.h>
24#include <ascii-chat/options/options.h>
25#include <ascii-chat/options/rcu.h>
26#include <ascii-chat/discovery/strings.h>
59static _Atomic(shutdown_check_fn) g_shutdown_callback = NULL;
61void shutdown_register_callback(shutdown_check_fn callback) {
62 atomic_store(&g_shutdown_callback, callback);
66 shutdown_check_fn callback = atomic_load(&g_shutdown_callback);
67 if (callback == NULL) {
78#if defined(DEBUG_MEMORY) && !defined(USE_MIMALLOC_DEBUG) && !defined(NDEBUG)
79#include <ascii-chat/debug/memory.h>
80#elif defined(USE_MIMALLOC_DEBUG) && !defined(NDEBUG)
81static void print_mimalloc_stats(
void);
87static bool g_shared_initialized =
false;
96static void asciichat_common_atfork_child(
void) {
98 g_shared_initialized =
false;
104__attribute__((constructor))
static void register_common_fork_handlers(
void) {
105 pthread_atfork(NULL, NULL, asciichat_common_atfork_child);
117 if (!g_shared_initialized) {
120 FATAL(ERROR_PLATFORM_INIT,
"Failed to initialize timer system");
127 log_init(log_file, LOG_DEBUG, force_stderr,
false );
131 FATAL(ERROR_PLATFORM_INIT,
"Failed to initialize platform");
138 g_shared_initialized =
true;
166 static bool shutdown_done =
false;
170 shutdown_done =
true;
177 extern void terminal_stop_resize_detection(
void);
178 terminal_stop_resize_detection();
218 extern void keyboard_destroy(
void);
234#if defined(USE_MIMALLOC_DEBUG) && !defined(NDEBUG)
235 print_mimalloc_stats();
238#if defined(DEBUG_MEMORY) && !defined(NDEBUG)
239 debug_memory_report();
250#if defined(USE_MIMALLOC_DEBUG) && !defined(NDEBUG)
253static void print_mimalloc_stats(
void) {
259 mi_stats_print(NULL);
void asciichat_errno_destroy(void)
void buffer_pool_cleanup_global(void)
void buffer_pool_init_global(void)
void colorscheme_destroy(void)
__attribute__((constructor))
Register fork handlers for common module.
ASCIICHAT_API bool g_color_flag_value
ASCIICHAT_API bool g_color_flag_passed
ASCIICHAT_API char ** g_argv
asciichat_error_t asciichat_shared_init(const char *log_file, bool is_client)
bool shutdown_is_requested(void)
void asciichat_shared_destroy(void)
Clean up all shared library subsystems.
void acds_strings_destroy(void)
Cleanup function for session string cache Called by asciichat_shared_destroy() during library cleanup...
void platform_destroy(void)
asciichat_error_t platform_init(void)
void known_hosts_destroy(void)
bool has_action_flag(void)
Check if an action flag was detected.
void lock_debug_cleanup_thread(void)
void lock_debug_destroy(void)
void log_shutdown_end(void)
void log_cleanup_colors(void)
Clean up compiled color scheme.
void log_shutdown_begin(void)
void log_init(const char *filename, log_level_t level, bool force_stderr, bool use_mmap)
void asciichat_pcre2_cleanup_all(void)
Free all PCRE2 singletons in the global registry.
void options_state_destroy(void)
void timer_system_destroy(void)
bool timer_system_init(void)
void simd_caches_destroy_all(void)
void webcam_destroy(void)