Suckless OGL 1.0.0
A lean, high-performance C11 PBR Renderer
Loading...
Searching...
No Matches
app_subsystem.h File Reference

Subsystem descriptor pattern for structured init/cleanup. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  SubsystemDescriptor
 Describes one subsystem's lifecycle hooks. More...
 

Functions

int app_subsystems_init (struct App *app, const SubsystemDescriptor *table)
 Walk table forward calling init() until the sentinel {0}.
 
void app_subsystems_cleanup (struct App *app, const SubsystemDescriptor *table)
 Walk table in reverse, calling cleanup() for each entry.
 

Detailed Description

Subsystem descriptor pattern for structured init/cleanup.

A SubsystemDescriptor is a {name, init, cleanup} triple. app_subsystems_init() walks the table forward, calling each init(); on failure it calls cleanup() in reverse for all previously-succeeded entries. app_subsystems_cleanup() walks the table in reverse, calling every non-NULL cleanup().

Function Documentation

◆ app_subsystems_cleanup()

void app_subsystems_cleanup ( struct App *  app,
const SubsystemDescriptor *  table 
)

Walk table in reverse, calling cleanup() for each entry.

Skips entries whose cleanup function pointer is NULL. The table must be terminated by a {0} sentinel entry. Intended for the normal shutdown path after a successful init.

◆ app_subsystems_init()

int app_subsystems_init ( struct App *  app,
const SubsystemDescriptor *  table 
)

Walk table forward calling init() until the sentinel {0}.

On the first failure at index N, cleanup() is called in reverse for entries [N-1 .. 0], then 0 is returned. The table must be terminated by a {0} sentinel entry.

Returns
1 if all init() calls succeed, 0 on first failure.