The Pedigree Project 0.1
Rcu.h
1/* Copyright (c) 2026, Pedigree Developers. SPDX-License-Identifier: ISC */
2#ifndef PEDIGREE_KERNEL_PROCESS_RCU_H
3#define PEDIGREE_KERNEL_PROCESS_RCU_H
4
5#include "pedigree/kernel/compiler.h"
6#include "pedigree/kernel/process/Mutex.h"
7#include "pedigree/kernel/process/RcuReadState.h"
8
17class EXPORTED_PUBLIC RcuReadGuard {
18 public:
21
22 private:
23 NOT_COPYABLE_OR_ASSIGNABLE(RcuReadGuard);
24 RcuReadState* m_State;
25 bool m_Interrupts;
26};
27
28template <typename T>
30 public:
31 RcuPointer() = default;
32 NOT_COPYABLE_OR_ASSIGNABLE(RcuPointer);
33
34 T* load(const RcuReadGuard&) const {
35 return __atomic_load_n(&m_Pointer, __ATOMIC_SEQ_CST);
36 }
37
39 T* loadForUpdate() const {
40 return __atomic_load_n(&m_Pointer, __ATOMIC_SEQ_CST);
41 }
42
44 T* exchange(T* replacement) {
45 return __atomic_exchange_n(&m_Pointer, replacement, __ATOMIC_SEQ_CST);
46 }
47
48 private:
49 T* m_Pointer = nullptr;
50};
51
52namespace Rcu {
58EXPORTED_PUBLIC void synchronize();
59} // namespace Rcu
60
69class EXPORTED_PUBLIC RcuRetireQueue {
70 public:
71 static constexpr size_t Capacity = 32;
72 using Reclaim = void (*)(void*);
73
74 RcuRetireQueue() = default;
76 void retire(void* object, Reclaim reclaim);
77 void drain();
78
79 private:
80 NOT_COPYABLE_OR_ASSIGNABLE(RcuRetireQueue);
81 void drainLocked();
82 Mutex m_Lock;
83 struct Entry {
84 void* object;
85 Reclaim reclaim;
86 } m_Entries[Capacity];
87 size_t m_Count = 0;
88};
89
90#endif
Definition Mutex.h:56
T * exchange(T *replacement)
Definition Rcu.h:44
T * loadForUpdate() const
Definition Rcu.h:39