ZXFoundation™ 26h2
Loading...
Searching...
No Matches
core.cxxm
1/// SPDX-License-Identifier: Apache-2.0
2/// @file zxfoundation/rcu/rcu.cxxm
3/// @brief Read-Copy-Update — non-preemptive SMP implementation.
4
5export module zxfoundation.sync.rcu.core;
6import zxfoundation.sync.rcu.types;
7import arch.s390x.cpu.sync;
8import std;
9
10export {
11
12namespace zxfoundation::sync::rcu {
13
14 auto init() noexcept -> void;
15
16 /// @brief Enter an RCU read-side critical section.
17 auto read_lock() noexcept -> void;
18
19 /// @brief Exit an RCU read-side critical section.
20 auto read_unlock() noexcept -> void;
21
22 /// @brief RAII RCU read-side guard (inline OK — calls exported non-TU-local functions).
23 class read_guard {
24 public:
25 read_guard() noexcept { read_lock(); }
26 ~read_guard() noexcept { read_unlock(); }
27 read_guard(const read_guard&) = delete;
28 auto operator=(const read_guard&) = delete;
29 };
30
31 /// @brief Load a RCU-protected pointer with acquire semantics.
32 template<typename T>
33 [[nodiscard]] auto dereference(T* const& ptr) noexcept -> T* {
34 arch::s390x::cpu::sync::barrier();
35 T* v;
36 __atomic_load(&ptr, &v,
37 static_cast<int>(std::memory_order::acquire));
38 return v;
39 }
40
41 /// @brief Publish a pointer with release semantics.
42 template<typename T>
43 auto assign_pointer(T*& ptr, T* v) noexcept -> void {
44 __atomic_store(&ptr, &v,
45 static_cast<int>(std::memory_order::release));
46 }
47
48 /// @brief Enqueue a deferred callback after the next grace period.
49 auto call_rcu(rcu_head* head, void(*func)(rcu_head*) noexcept) noexcept -> void;
50
51 /// @brief Block until all pre-existing RCU readers complete.
52 auto synchronize_rcu() noexcept -> void;
53
54 /// @brief Wait until all enqueued call_rcu callbacks have fired.
55 auto barrier() noexcept -> void;
56
57 /// @brief Per-CPU RCU tick: report QS, manage GPs, drain callbacks.
58 auto tick() noexcept -> void;
59
60} // namespace zxfoundation::rcu
61
62} // end export