ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
Go to the documentation of this file.
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/dgp/domain.zcomponent/core.cxxm
3/// @brief Domain subsystem interface — domain, strand, and lifecycle
4/// management entry points.
5
6export module zxfoundation.dgp.domain.core;
7import zxfoundation.dgp.domain.types;
8import zxfoundation.scoms.table;
9import zxfoundation.base.types;
10import lib.error;
11import std;
12
13/// @brief The global domain table — SCOMS scoms_table.
14from_global(nomangle) namespace zxfoundation::dgp::domain {
15 scoms::scoms_table<domain, MAX_DOMAINS> g_domain_table;
16}
17
18export {
19
20namespace zxfoundation::dgp::domain {
21
22 /// @brief Initialize the strand SCOMS table.
23 auto strand_init() noexcept -> void;
24
25 /// @brief Allocate a per-CPU idle strand from the SCOMS strand table.
26 /// @param cpu CPU this idle strand is pinned to.
27 /// @return Pointer to the idle strand, or kernel_error.
28 /// @note Idle strands have owner == nullptr and strand_flags::idle set.
29 [[nodiscard]] auto idle_strand_create(u16 cpu) noexcept
30 -> std::expected<strand*, lib::kernel_error>;
31
32 /// @brief Destroy a per-CPU idle strand and release its SCOMS slot.
33 /// @param s Idle strand to destroy.
34 /// @return Success or kernel_error.
35 [[nodiscard]] auto idle_strand_destroy(strand& s) noexcept
36 -> std::expected<void, lib::kernel_error>;
37
38 /// @brief Create a secondary strand within a domain.
39 /// @param owner Domain that will own the strand.
40 /// @param cpu CPU affinity (0 for any, or specific CPU).
41 /// @return Pointer to the created strand, or kernel_error.
42 [[nodiscard]] auto strand_create(
43 domain* owner, u16 cpu = 0
44 ) noexcept -> std::expected<strand*, lib::kernel_error>;
45
46 /// @brief Destroy a secondary strand that has already left all run queues.
47 /// @param[in,out] s Strand whose stack and SCOMS identity should be released.
48 /// @return Success or kernel_error when the strand is still runnable or invalid.
49 [[nodiscard]] auto strand_destroy(strand& s) noexcept -> std::expected<void, lib::kernel_error>;
50
51 /// @brief Create a new domain.
52 /// @param[in] name Human-readable name (pointer must remain valid for
53 /// the domain's lifetime).
54 /// @return Pointer to the newly created and activated domain, or kernel_error.
55 [[nodiscard]] auto domain_create(const char* name) noexcept
56 -> std::expected<domain*, lib::kernel_error>;
57
58 /// @brief Destroy a domain and release all its resources.
59 /// @param[in] id Domain ID to destroy.
60 /// @return Success or kernel_error on invalid ID or an already-claimed domain.
61 [[nodiscard]] auto domain_destroy(domain_id id) noexcept
62 -> std::expected<void, lib::kernel_error>;
63
64 /// @brief Look up a domain by ID.
65 /// @param[in] id Domain ID.
66 /// @return Pointer to the domain, or nullptr if the slot is unused or
67 /// the ID is out of range.
68 [[nodiscard]] auto domain_find(domain_id id) noexcept -> domain*;
69
70 /// @brief Activate a domain: transition from embryo → active.
71 /// @param[in] id Domain ID to activate.
72 /// @return Success, or kernel_error if the domain is not in embryo state.
73 [[nodiscard]] auto domain_activate(domain_id id) noexcept
74 -> std::expected<void, lib::kernel_error>;
75
76 /// @brief Return the current number of live domains.
77 [[nodiscard]] auto domain_count() noexcept -> u32;
78
79 /// @brief Invoke @p fn for every live domain in the system.
80 /// @tparam Fn Callable of signature @c bool(domain&) noexcept.
81 /// @param[in] fn Visitor. Return @c true to continue, @c false to stop.
82 /// @return Number of domains visited.
83 template <typename Fn>
84 auto domain_for_each(Fn&& fn) noexcept -> u32 {
85 return g_domain_table.for_each(static_cast<Fn&&>(fn));
86 }
87
88 auto register_domain_cap_lookup() noexcept -> void;
89
90 /// @brief Initialize the domain subsystem.
91 auto domain_init() noexcept -> void;
92
93 /// @brief Get the nucleus domain — the kernel's own domain identity.
94 /// @return Pointer to the nucleus domain (slot 0). Always non-null
95 /// after @ref domain_init_nucleus has been called.
96 [[nodiscard]] auto domain_nucleus() noexcept -> domain*;
97
98 /// @brief Return the currently-running domain
99 [[nodiscard]] auto current_domain_or_nucleus() noexcept -> domain*;
100
101 /// @brief Initialize the nucleus domain at slot 0.
102 [[nodiscard]] auto domain_init_nucleus() noexcept
103 -> std::expected<void, lib::kernel_error>;
104
105} // namespace zxfoundation::dgp::domain
106
107} // end export