ascii-chat 0.11.33
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.
 
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 <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 <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 73 of file common.c.

73 {
74 shutdown_check_fn callback = (shutdown_check_fn)atomic_ptr_load(&g_shutdown_callback);
75 if (callback == NULL) {
76 return false; // No callback registered, assume not shutting down
77 }
78 return callback();
79}
void * atomic_ptr_load(atomic_ptr_t *a)
Atomically load a pointer.
Definition atomic.c:272
bool(* shutdown_check_fn)(void)
Shutdown check callback function type.
Definition shutdown.h:32

References atomic_ptr_load().

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

◆ shutdown_register_callback()

void shutdown_register_callback ( shutdown_check_fn  callback)

#include <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 69 of file common.c.

69 {
70 atomic_ptr_store(&g_shutdown_callback, (void *)callback);
71}
void atomic_ptr_store(atomic_ptr_t *a, void *value)
Atomically store a pointer.
Definition atomic.c:280

References atomic_ptr_store().

Referenced by main(), and server_main().