KWin
Loading...
Searching...
No Matches
src
utils
memorymap.h
Go to the documentation of this file.
1
/*
2
SPDX-FileCopyrightText: 2023 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
3
4
SPDX-License-Identifier: GPL-2.0-or-later
5
*/
6
7
#pragma once
8
9
#include <sys/mman.h>
10
#include <utility>
11
12
namespace
KWin
13
{
14
15
class
MemoryMap
16
{
17
public
:
18
MemoryMap
()
19
: m_data(MAP_FAILED)
20
, m_size(0)
21
{
22
}
23
24
MemoryMap
(
int
size
,
int
prot,
int
flags,
int
fd, off_t offset)
25
: m_data(mmap(nullptr,
size
, prot, flags, fd, offset))
26
, m_size(
size
)
27
{
28
}
29
30
MemoryMap
(
MemoryMap
&&other)
31
: m_data(std::exchange(other.m_data, MAP_FAILED))
32
, m_size(std::exchange(other.m_size, 0))
33
{
34
}
35
36
~MemoryMap
()
37
{
38
if
(m_data != MAP_FAILED) {
39
munmap(m_data, m_size);
40
}
41
}
42
43
MemoryMap
&
operator=
(
MemoryMap
&&other)
44
{
45
if
(m_data != MAP_FAILED) {
46
munmap(m_data, m_size);
47
}
48
m_data = std::exchange(other.m_data, MAP_FAILED);
49
m_size = std::exchange(other.m_size, 0);
50
return
*
this
;
51
}
52
53
inline
bool
isValid
()
const
54
{
55
return
m_data != MAP_FAILED;
56
}
57
58
inline
void
*
data
()
const
59
{
60
return
m_data;
61
}
62
63
inline
int
size
()
const
64
{
65
return
m_size;
66
}
67
68
private
:
69
void
*m_data;
70
int
m_size;
71
};
72
73
}
// namespace KWin
KWin::MemoryMap
Definition
memorymap.h:16
KWin::MemoryMap::data
void * data() const
Definition
memorymap.h:58
KWin::MemoryMap::operator=
MemoryMap & operator=(MemoryMap &&other)
Definition
memorymap.h:43
KWin::MemoryMap::isValid
bool isValid() const
Definition
memorymap.h:53
KWin::MemoryMap::~MemoryMap
~MemoryMap()
Definition
memorymap.h:36
KWin::MemoryMap::MemoryMap
MemoryMap()
Definition
memorymap.h:18
KWin::MemoryMap::MemoryMap
MemoryMap(MemoryMap &&other)
Definition
memorymap.h:30
KWin::MemoryMap::MemoryMap
MemoryMap(int size, int prot, int flags, int fd, off_t offset)
Definition
memorymap.h:24
KWin::MemoryMap::size
int size() const
Definition
memorymap.h:63
KWin
Definition
activation_test.cpp:20
Generated on Sat Feb 17 2024 01:42:10 for KWin by
1.10.0