ascii-chat
Binary v0.15.83-53-gb711d8720
Library lib/v0.3.2-701-gb711d8720
Video chat in your terminal
Loading...
Searching...
No Matches
Shutdown System

Clean shutdown detection without library accessing application state. More...

Files

file  shutdown.h
 Shutdown check system for clean library/application separation.

Typedefs

typedef bool(* shutdown_check_fn) (void)
 Shutdown check callback function type.

Functions

void shutdown_register_callback (shutdown_check_fn callback)
 Register application's shutdown check function.
void shutdown_request (void)
bool shutdown_is_requested (void)
 Check if shutdown has been requested.

Detailed Description

Clean shutdown detection without library accessing application state.

Provides clean separation between library and application for shutdown detection. Library code should never directly access application state.

Usage: Application (server.c/client.c): shutdown_register_callback(my_shutdown_check_fn);

Library code (logging.c, debug/lock.c, etc.): if (shutdown_is_requested()) { return; }

Typedef Documentation

◆ shutdown_check_fn

typedef bool(* shutdown_check_fn) (void)

#include <include/ascii-chat/common/shutdown.h>

Shutdown check callback function type.

Returns
true if shutdown has been requested, false otherwise

Definition at line 32 of file shutdown.h.

Function Documentation

◆ shutdown_is_requested()

bool shutdown_is_requested ( void )

#include <include/ascii-chat/common/shutdown.h>

Check if shutdown has been requested.

Returns
true if shutdown has been requested, false otherwise
Note
Use this in library code to check for shutdown requests without accessing application state directly. The callback must be registered first with shutdown_register_callback().

Definition at line 86 of file common.c.

86 {
87 if (atomic_load_u64(&g_shutdown_requested)) {
88 return true;
89 }
90 shutdown_check_fn callback = (shutdown_check_fn)atomic_ptr_load(&g_shutdown_callback);
91 if (callback == NULL) {
92 return false; // No callback registered, assume not shutting down
93 }
94 return callback();
95}
bool(* shutdown_check_fn)(void)
Shutdown check callback function type.
Definition shutdown.h:32

Referenced by log_plain_msg(), log_plain_stderr_msg(), log_plain_stderr_nonewline_msg(), log_plain_stdout_msg(), splash_wait_for_animation(), stats_runtime_start(), ui_input_wait_key(), and update_banner_show_prompt().

◆ shutdown_register_callback()

void shutdown_register_callback ( shutdown_check_fn callback)

#include <include/ascii-chat/common/shutdown.h>

Register application's shutdown check function.

Parameters
callbackFunction to call to check if shutdown has been requested
Note
Call this from main() to register the application's shutdown detection function. Library code should use shutdown_is_requested() instead of accessing application state directly.

Definition at line 78 of file common.c.

78 {
79 atomic_ptr_store(&g_shutdown_callback, (void *)callback);
80}

Referenced by main(), and server_main().

◆ shutdown_request()

void shutdown_request ( void )

#include <include/ascii-chat/common/shutdown.h>

Request a clean application shutdown from shared library code.

Definition at line 82 of file common.c.

82 {
83 atomic_store_u64(&g_shutdown_requested, 1);
84}

Referenced by ui_input_password(), and update_banner_install_update().