lmms
Cross-platform music production software
Toggle main menu visibility
Loading...
Searching...
No Matches
include
LocklessAllocator.h
Go to the documentation of this file.
1
/*
2
* LocklessAllocator.h - allocator with lockless alloc and free
3
*
4
* Copyright (c) 2016 Javier Serrano Polo <javier@jasp.net>
5
*
6
* This file is part of LMMS - https://lmms.io
7
*
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU General Public
10
* License as published by the Free Software Foundation; either
11
* version 2 of the License, or (at your option) any later version.
12
*
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
* General Public License for more details.
17
*
18
* You should have received a copy of the GNU General Public
19
* License along with this program (see COPYING); if not, write to the
20
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21
* Boston, MA 02110-1301 USA.
22
*
23
*/
24
25
#ifndef LMMS_LOCKLESS_ALLOCATOR_H
26
#define LMMS_LOCKLESS_ALLOCATOR_H
27
28
#include <atomic>
29
#include <cstddef>
30
31
32
namespace
lmms
33
{
34
35
36
class
LocklessAllocator
37
{
38
public
:
39
LocklessAllocator
(
size_t
nmemb,
size_t
size );
40
virtual
~LocklessAllocator
();
41
void
*
alloc
();
42
void
free
(
void
* ptr );
43
44
45
private
:
46
char
*
m_pool
;
47
size_t
m_capacity
;
48
size_t
m_elementSize
;
49
50
std::atomic_int *
m_freeState
;
51
size_t
m_freeStateSets
;
52
53
std::atomic_size_t
m_available
;
54
std::atomic_size_t
m_startIndex
;
55
56
} ;
57
58
59
60
61
template
<
typename
T>
62
class
LocklessAllocatorT
:
private
LocklessAllocator
63
{
64
public
:
65
LocklessAllocatorT
(
size_t
nmemb ) :
66
LocklessAllocator
( nmemb, sizeof( T ) )
67
{
68
}
69
70
~LocklessAllocatorT
()
override
=
default
;
71
72
T *
alloc
()
73
{
74
return
(T *)
LocklessAllocator::alloc
();
75
}
76
77
void
free
( T * ptr )
78
{
79
LocklessAllocator::free
( ptr );
80
}
81
82
} ;
83
84
85
}
// namespace lmms
86
87
#endif
// LMMS_LOCKLESS_ALLOCATOR_H
lmms::LocklessAllocator::m_elementSize
size_t m_elementSize
Definition
LocklessAllocator.h:48
lmms::LocklessAllocator::m_available
std::atomic_size_t m_available
Definition
LocklessAllocator.h:53
lmms::LocklessAllocator::m_startIndex
std::atomic_size_t m_startIndex
Definition
LocklessAllocator.h:54
lmms::LocklessAllocator::free
void free(void *ptr)
Definition
LocklessAllocator.cpp:142
lmms::LocklessAllocator::m_freeStateSets
size_t m_freeStateSets
Definition
LocklessAllocator.h:51
lmms::LocklessAllocator::LocklessAllocator
LocklessAllocator(size_t nmemb, size_t size)
Definition
LocklessAllocator.cpp:55
lmms::LocklessAllocator::m_freeState
std::atomic_int * m_freeState
Definition
LocklessAllocator.h:50
lmms::LocklessAllocator::alloc
void * alloc()
Definition
LocklessAllocator.cpp:107
lmms::LocklessAllocator::m_pool
char * m_pool
Definition
LocklessAllocator.h:46
lmms::LocklessAllocator::m_capacity
size_t m_capacity
Definition
LocklessAllocator.h:47
lmms::LocklessAllocatorT::LocklessAllocatorT
LocklessAllocatorT(size_t nmemb)
Definition
LocklessAllocator.h:65
lmms::LocklessAllocatorT::free
void free(T *ptr)
Definition
LocklessAllocator.h:77
lmms::LocklessAllocatorT::~LocklessAllocatorT
~LocklessAllocatorT() override=default
lmms::LocklessAllocatorT::alloc
T * alloc()
Definition
LocklessAllocator.h:72
lmms
Definition
RemotePluginBase.cpp:34
Generated on
for lmms by
1.18.0