MOS Source Code
Loading...
Searching...
No Matches
refcount.hpp
Go to the documentation of this file.
1
// SPDX-License-Identifier: GPL-3.0-or-later
2
3
#pragma once
4
5
#include <atomic>
6
#include <cstddef>
7
#include <
mos/allocator.hpp
>
8
#include <
mos/type_utils.hpp
>
9
10
namespace
mos
11
{
12
struct
RCCore
13
{
14
std::atomic_size_t
n
= 0;
15
void
Ref
()
16
{
17
n
++;
18
}
19
20
void
Unref
()
21
{
22
n
--;
23
}
24
};
25
26
struct
RefCounted
27
{
28
protected
:
29
explicit
RefCounted
(
RCCore
*rc_) :
rc
(rc_)
30
{
31
rc
->Ref();
32
}
33
34
RefCounted
(
const
RefCounted
&a) :
rc
(a.
rc
)
35
{
36
rc
->Ref();
37
}
38
39
RefCounted
(
RefCounted
&&a) :
rc
(a.
rc
)
40
{
41
a.rc =
nullptr
;
42
}
43
44
~RefCounted
()
45
{
46
if
(
rc
)
47
{
48
rc
->Unref();
49
}
50
}
51
52
RefCounted
operator=
(
const
RefCounted
&a) =
delete
;
53
RefCounted
operator=
(
RefCounted
&&a) =
delete
;
54
55
protected
:
56
size_t
GetRef
()
const
57
{
58
return
rc
->n;
59
}
60
61
private
:
62
RCCore
*
rc
=
nullptr
;
63
};
64
}
// namespace mos
allocator.hpp
mos
Definition
allocator.hpp:10
mos::RCCore
Definition
refcount.hpp:13
mos::RCCore::Unref
void Unref()
Definition
refcount.hpp:20
mos::RCCore::Ref
void Ref()
Definition
refcount.hpp:15
mos::RCCore::n
std::atomic_size_t n
Definition
refcount.hpp:14
mos::RefCounted::RefCounted
RefCounted(RefCounted &&a)
Definition
refcount.hpp:39
mos::RefCounted::operator=
RefCounted operator=(RefCounted &&a)=delete
mos::RefCounted::rc
RCCore * rc
Definition
refcount.hpp:62
mos::RefCounted::RefCounted
RefCounted(const RefCounted &a)
Definition
refcount.hpp:34
mos::RefCounted::operator=
RefCounted operator=(const RefCounted &a)=delete
mos::RefCounted::RefCounted
RefCounted(RCCore *rc_)
Definition
refcount.hpp:29
mos::RefCounted::GetRef
size_t GetRef() const
Definition
refcount.hpp:56
mos::RefCounted::~RefCounted
~RefCounted()
Definition
refcount.hpp:44
type_utils.hpp
kernel
include
libs
mos
refcount.hpp
Generated on Sat Mar 1 2025 10:32:59 for MOS Source Code by
1.13.2