libxtc 0.4.0
Async concurrency for C: Tokio + Seastar + BEAM, in one library
Loading...
Searching...
No Matches
xtc_sched.h
1/*-
2 * Copyright (c) 2026, The XTC Project
3 * @stability experimental
4 * Use of this source code is governed by the ISC License.
5 */
6#ifndef XTC_SCHED_H
7#define XTC_SCHED_H
8
9#include <stddef.h>
10#include <stdint.h>
11#include "xtc_loop.h"
12
13#define XTC_SCHED_VERSION 1
14/* Defer to the ordinary picker; lane -1 is the actual default lane. */
15#define XTC_SCHED_DEFAULT (-2)
16
17typedef struct xtc_sched_lane {
18 int32_t id;
19 uint32_t shares;
20 uint64_t runs, bypasses;
21 /* Advisory batch counts; never establish runqueue readiness. */
22 uint32_t ready, active;
24
25typedef struct xtc_sched_view {
26 const xtc_sched_lane_t *lanes;
27 size_t count;
29
30enum xtc_sched_verdict {
31 XTC_SCHED_DONE, XTC_SCHED_YIELD, XTC_SCHED_PARK
32};
33typedef struct xtc_sched_run {
34 int32_t lane;
35 enum xtc_sched_verdict verdict;
36 uint64_t units;
38
39typedef struct xtc_sched_policy {
40 uint32_t size, version;
41 uint32_t max_bypass;
42 int32_t (*select)(const xtc_sched_view_t *, void *);
43 void (*ran)(const xtc_sched_run_t *, void *);
44 void *user;
46
47typedef struct xtc_sched_stats {
48 uint32_t size, version;
49 uint64_t selections, fallbacks, invalid_choices, fairness_overrides;
51
52#ifdef __cplusplus
53extern "C" {
54#endif
55/* Copy descriptor; borrow callback/context through loop teardown. Setup only,
56 * frozen by the first run/step (even empty). NULL removes before first run.
57 * Callbacks must not block, yield, allocate, or mutate runtime state. */
58XTC_API int xtc_sched_policy_set(xtc_loop_t *, const xtc_sched_policy_t *);
59/* Install loop-owned continuous batch-lane preference before first run. */
60XTC_API int xtc_sched_continuous_set(xtc_loop_t *, uint32_t max_bypass);
61/* Owner/quiescent reads only. Initialize size and version before calling. */
62XTC_API int xtc_sched_get_stats(xtc_loop_t *, xtc_sched_stats_t *);
63#ifdef __cplusplus
64}
65#endif
66#endif