libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
proc_int.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/proc_int.h
6 * Internal process primitives that are not part of the consumer
7 * API. Split out of xtc_proc.h so no __-prefixed symbol leaks into
8 * an installed public header.
9 *
10 * (The recovery-frame __xtc_recovery_* / __xtc_proc_recovery_slot
11 * decls stay in xtc_proc.h: the PUBLIC macro xtc_proc_recovery_arm()
12 * expands to them, so they must be visible in the consumer's TU.
13 * These context save/restore helpers are called only from within
14 * the library, so they belong here.)
15 */
16
17#ifndef XTC_PROC_INT_H
18#define XTC_PROC_INT_H
19
20#include "xtc_proc.h"
21
22/* Owner/quiescent lookup on a live loop, including procs still in exit hooks.
23 * PIDs are executor-relative; a global info scan cannot establish this join. */
24int __xtc_proc_loop_contains(xtc_loop_t *, xtc_pid_t);
25
26/* The calling proc's OWNER loop: the one it was spawned on, whose table
27 * holds its slot (p->loop). Unchanged by work-stealing migration, so it
28 * is NOT necessarily the loop the fiber is running on. NULL off a proc.
29 * *out_pid (if non-NULL) gets the same proc's pid. (pid, owner) is an
30 * unambiguous identity; record it on the proc's own fiber. */
31xtc_loop_t *__xtc_proc_self_loop(xtc_pid_t *out_pid);
32
33/* xtc_exit_pid_deadline resolved in `owner`'s table only, so an equal pid
34 * on another loop is never signalled. owner must be non-NULL and alive
35 * (not finalized) for the call; XTC_E_INVAL if NULL. */
36int __xtc_exit_pid_deadline_on(xtc_loop_t *owner, xtc_pid_t target,
37 int reason, int64_t timeout_ns, int *out_status);
38
39/* xtc_exit_pid / xtc_send resolved in `owner`'s table only (same owner
40 * contract as above; XTC_E_INVAL if owner is NULL). */
41int __xtc_exit_pid_on(xtc_loop_t *owner, xtc_pid_t target, int reason);
42int __xtc_send_on(xtc_loop_t *owner, xtc_pid_t to, const void *data,
43 size_t size);
44
45/* Test seam: set the generation of a FREE slot on `loop` (see proc.c). */
46int __xtc_proc_slot_gen_set(xtc_loop_t *loop, uint32_t local_id,
47 uint64_t gen);
48
49/*
50 * Save / restore the current-proc context across a yield done by a
51 * lower-level primitive (e.g. xtc_amutex parking the fiber), so the
52 * proc still sees itself on resume. Opaque to the caller.
53 */
54void *__xtc_proc_ctx_save(void);
55void __xtc_proc_ctx_restore(void *ctx);
56
57/*
58 * Exit the calling proc with `reason` and an explicit DOWN `kind`
59 * (xtc_down_kind_t) rather than the CLEAN/EXIT xtc_exit_self infers from
60 * the code. For a proc that reports someone else's fate as its own --
61 * the xproc shadow standing in for an OS child killed by a signal.
62 * Does not return on success; XTC_E_INVAL off a proc or for a bad kind.
63 */
64int __xtc_exit_self_kind(int reason, int kind);
65
66/*
67 * A3 async causal trace hook: record one suspend/resume boundary on the
68 * CALLING proc's per-fiber ring. `kind` is an enum xtc_causal_kind and
69 * `site` a static string label (e.g. __func__). A no-op fast path (one
70 * relaxed load + branch) when the causal trace is disabled or off a
71 * proc, so a default build writes nothing on the park/resume path.
72 * Single-writer / core-private: called only on the proc's own fiber.
73 */
74void __xtc_trace_causal(int kind, const char *site);
75
76/*
77 * Deliver a kill pending on the calling proc, at a park site's safe
78 * point (after it has dequeued its waiter, returned any grant, cancelled
79 * its park timer and dropped its locks). No-op off a proc, when no kill
80 * is pending, or when the kill is masked (it is latched, as at any other
81 * delivery point); otherwise unwinds via xtc_exit_self. The resume hook
82 * inside xtc_yield does NOT deliver after a park yield, so a park site
83 * that never calls this simply sees the kill at the proc's next delivery
84 * point.
85 */
86void __xtc_proc_kill_poll(void);
87
88/* Unbind any xtc_cfg session bound by task `t` (cfg.c). Called on the
89 * proc exit path after the at-exit hooks, before the task can be
90 * recycled for another proc. */
91void __xtc_cfg_task_exit(xtc_task_t *t);
92
93/* xtc_exit_pid makes a target parked anywhere runnable (except inside
94 * xtc_await), so a park site re-checks promptly and can deliver the kill. */
95#define XTC_HAVE_PROC_KILL_WAKE 1
96
97#endif /* XTC_PROC_INT_H */