ZXFoundation™ 26h2
Loading...
Searching...
No Matches
base.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/scoms/scoms_types.cxxm
3/// @brief SCOMS — Scalable Object Management System — core types.
4
5export module zxfoundation.scoms.kobject.base;
6import zxfoundation.scoms.kobject.types;
7import zxfoundation.sync.qspinlock.core;
8import zxfoundation.base.types;
9
10export {
11
12namespace zxfoundation::scoms::kobject {
13
14 /// @brief The kernel object header — embedded at offset 0 of every
15 /// SCOMS-managed resource.
16 struct bobject {
17 u32 id{~0U};
18 kobject::kobject_type type{kobject::kobject_type::none};
19 lifecycle_state state{lifecycle_state::embryo};
20 u8 _pad0[2]{};
21 kref ref{};
22 u32 generation{0};
23 sync::qspinlock::qspinlock lock{};
24 u32 object_flags{0};
25
26 bobject() noexcept = default;
27
28 /// @brief Validate and perform one canonical lifecycle transition.
29 [[nodiscard]] auto transition(lifecycle_state target) noexcept -> bool;
30
31 /// @brief Acquire a lifetime reference without resurrecting retirement.
32 [[nodiscard]] auto try_get() noexcept -> bool;
33
34 /// @brief Drop a lifetime reference and reclaim on the final put.
35 auto put() noexcept -> void;
36
37 /// @brief Reset identity and relationship metadata for a new slot use.
38 auto initialize(u32 object_id, kobject::kobject_type object_type) noexcept -> void;
39
40 // Non-copyable, non-movable — identity object.
41 bobject(const bobject&) = delete;
42 auto operator=(const bobject&) = delete;
43 bobject(bobject&&) = delete;
44 auto operator=(bobject&&) = delete;
45 };
46
47 static_assert(sizeof(bobject) == 24, "kobject ABI must remain exactly 24 bytes");
48 static_assert(__builtin_offsetof(bobject, id) == 0);
49 static_assert(__builtin_offsetof(bobject, type) == 4);
50 static_assert(__builtin_offsetof(bobject, state) == 5);
51 static_assert(__builtin_offsetof(bobject, ref) == 8);
52 static_assert(__builtin_offsetof(bobject, generation) == 12);
53 static_assert(__builtin_offsetof(bobject, lock) == 16);
54
55 using bobject_finalizer_fn = void (*)(bobject&) noexcept;
56
57 /// @brief Install the SCOMS metadata finalizer used after the last put.
58 auto install_bobject_finalizer(bobject_finalizer_fn finalizer) noexcept -> void;
59
60} // namespace zxfoundation::scoms
61
62} // end export