The Pedigree Project
0.1
src
system
include
pedigree
kernel
process
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
17
class
EXPORTED_PUBLIC
RcuReadGuard
{
18
public
:
19
RcuReadGuard
();
20
~RcuReadGuard
();
21
22
private
:
23
NOT_COPYABLE_OR_ASSIGNABLE(
RcuReadGuard
);
24
RcuReadState
* m_State;
25
bool
m_Interrupts;
26
};
27
28
template
<
typename
T>
29
class
RcuPointer
{
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
52
namespace
Rcu {
58
EXPORTED_PUBLIC
void
synchronize();
59
}
// namespace Rcu
60
69
class
EXPORTED_PUBLIC
RcuRetireQueue
{
70
public
:
71
static
constexpr
size_t
Capacity = 32;
72
using
Reclaim = void (*)(
void
*);
73
74
RcuRetireQueue
() =
default
;
75
~RcuRetireQueue
();
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
Mutex
Definition
Mutex.h:56
RcuPointer
Definition
Rcu.h:29
RcuPointer::exchange
T * exchange(T *replacement)
Definition
Rcu.h:44
RcuPointer::loadForUpdate
T * loadForUpdate() const
Definition
Rcu.h:39
RcuReadGuard
Definition
Rcu.h:17
RcuReadState
Definition
RcuReadState.h:9
RcuRetireQueue
Definition
Rcu.h:69
RcuRetireQueue::Entry
Definition
Rcu.h:83
Generated on Thu Sep 24 2026 06:24:01 for The Pedigree Project by
1.9.8