ascii-chat
Binary v0.16.114-28-gf5913657f
Library lib/v0.3.2-3302-gf5913657f
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 36 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 87 of file common.c.

87 {
88 if (atomic_load_u64(&g_shutdown_requested)) {
89 return true;
90 }
91 shutdown_check_fn callback =
92 (shutdown_check_fn)atomic_ptr_load(&g_shutdown_callback);
93 if (callback == NULL) {
94 return false; // No callback registered, assume not shutting down
95 }
96 return callback();
97}
void * atomic_ptr_load(atomic_ptr_t *a)
Atomically load a pointer.
uint64_t atomic_load_u64(const atomic_t *a)
Atomically load a uint64_t value.
bool(* shutdown_check_fn)(void)
Shutdown check callback function type.
Definition shutdown.h:36

References atomic_load_u64(), and atomic_ptr_load().

Referenced by asciichat_shared_destroy(), log_plain_msg(), log_plain_stderr_msg(), log_plain_stderr_nonewline_msg(), log_plain_stdout_msg(), session_pipeline_destroy(), splash_wait_for_animation(), stats_runtime_start(), ui_controller_write(), 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 81 of file common.c.

81 {
82 atomic_ptr_store(&g_shutdown_callback, (void *)callback);
83}
void atomic_ptr_store(atomic_ptr_t *a, void *value)
Atomically store a pointer.

References atomic_ptr_store().

Referenced by 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 85 of file common.c.

85{ atomic_store_u64(&g_shutdown_requested, 1); }
void atomic_store_u64(atomic_t *a, uint64_t value)
Atomically store a uint64_t value.

References atomic_store_u64().

Referenced by ui_input_password(), and update_banner_install_update().