libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_app.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * Use of this source code is governed by the ISC License.
4 *
5 * src/inc/xtc_app.h
6 * The L4 application container: a root supervisor + a process
7 * registry + lifecycle plumbing. Models OTP's `application`
8 * concept. An xtc_app owns a loop (creating one if not given
9 * or borrowing one passed in), starts a top-level supervisor
10 * with the configured children, and exposes the registry that
11 * those children can use to find each other by name.
12 *
13 * Typical usage:
14 *
15 * xtc_app_t *app;
16 * xtc_app_opts_t opts = XTC_APP_OPTS_DEFAULT;
17 * xtc_app_create(&opts, &app);
18 * xtc_app_start(app, child_specs, n_children);
19 * xtc_app_run(app); // blocks until app stops
20 * xtc_app_destroy(app);
21 */
22
23#ifndef XTC_APP_H
24#define XTC_APP_H
25
26#include "xtc_export.h"
27
28#include <stddef.h>
29
30#include "xtc.h"
31#include "xtc_loop.h"
32#include "xtc_exec.h"
33#include "xtc_orc.h"
34#include "xtc_reg.h"
35
36typedef struct xtc_app xtc_app_t;
37
38typedef struct xtc_app_opts {
39 const char *name; /* optional, for logs */
40 xtc_loop_t *loop; /* optional; NULL = create one */
41 int n_loops; /* >1 = own an N-loop executor and run
42 * the root supervisor on loop 0 (the
43 * other loops host children placed via
44 * xtc_child_spec.loop, and any work the
45 * children spawn via xtc_app_exec); 0/1
46 * = single loop. Ignored when `loop`
47 * is supplied. */
48 xtc_sup_opts_t sup; /* root-supervisor settings */
49 int no_tuning_check; /* 1 = skip the __os_tuning_check()
50 * power/kernel-tuning advisor probe
51 * xtc_app_start runs by default
52 * (PLAN.md 19.21); additive field,
53 * appended last -- see
54 * docs/abi-stability.md. */
56
57#define XTC_APP_OPTS_DEFAULT { \
58 .name = NULL, \
59 .loop = NULL, \
60 .n_loops = 1, \
61 .sup = XTC_SUP_OPTS_DEFAULT, \
62 .no_tuning_check = 0 \
63}
64
65/*
66 * PUBLIC: int xtc_app_create __P((const xtc_app_opts_t *, xtc_app_t **));
67 * PUBLIC: void xtc_app_destroy __P((xtc_app_t *));
68 * PUBLIC: int xtc_app_start __P((xtc_app_t *, const xtc_child_spec_t *, int));
69 * PUBLIC: int xtc_app_run __P((xtc_app_t *));
70 * PUBLIC: int xtc_app_stop __P((xtc_app_t *));
71 * PUBLIC: xtc_loop_t *xtc_app_loop __P((const xtc_app_t *));
72 * PUBLIC: xtc_exec_t *xtc_app_exec __P((const xtc_app_t *));
73 * PUBLIC: xtc_reg_t *xtc_app_registry __P((const xtc_app_t *));
74 */
75
76XTC_API int xtc_app_create(const xtc_app_opts_t *opts, xtc_app_t **out);
77XTC_API void xtc_app_destroy(xtc_app_t *app);
78
79/* Start the root supervisor with `n_children` initial children. */
80XTC_API int xtc_app_start(xtc_app_t *app,
81 const xtc_child_spec_t *children,
82 int n_children);
83
84/* Run the loop until the supervisor exits or xtc_app_stop is called.
85 * On return, xtc_app_destroy may be called. */
86XTC_API int xtc_app_run(xtc_app_t *app);
87
88/* Asynchronously request the app to stop (kicks the root sup). */
89XTC_API int xtc_app_stop(xtc_app_t *app);
90
91XTC_API xtc_loop_t *xtc_app_loop(const xtc_app_t *app);
92
93/* The executor backing a multi-loop app (n_loops > 1), or NULL for a
94 * single-loop app. Children use it to spawn work across loops -- e.g.
95 * a listener spawning a proc per connection round-robin. */
96XTC_API xtc_exec_t *xtc_app_exec(const xtc_app_t *app);
97
98XTC_API xtc_reg_t *xtc_app_registry(const xtc_app_t *app);
99
100#endif /* XTC_APP_H */