Remove MemoryManager (#7128)
Removes `MemoryManager` and the use of rpmalloc in favor of the `new` and `delete` operators found in C++. --------- Co-authored-by: Veratil <veratil@gmail.com>
This commit is contained in:
1
src/3rdparty/CMakeLists.txt
vendored
1
src/3rdparty/CMakeLists.txt
vendored
@@ -4,7 +4,6 @@ IF(LMMS_BUILD_LINUX AND WANT_VST)
|
||||
ENDIF()
|
||||
|
||||
ADD_SUBDIRECTORY(hiir)
|
||||
ADD_SUBDIRECTORY(rpmalloc)
|
||||
ADD_SUBDIRECTORY(weakjack)
|
||||
|
||||
if(MINGW)
|
||||
|
||||
49
src/3rdparty/rpmalloc/CMakeLists.txt
vendored
49
src/3rdparty/rpmalloc/CMakeLists.txt
vendored
@@ -1,49 +0,0 @@
|
||||
add_library(rpmalloc STATIC
|
||||
rpmalloc/rpmalloc/rpmalloc.c
|
||||
rpmalloc/rpmalloc/rpmalloc.h
|
||||
)
|
||||
|
||||
target_include_directories(rpmalloc PUBLIC
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/rpmalloc/rpmalloc
|
||||
)
|
||||
|
||||
set_property(TARGET rpmalloc PROPERTY C_STANDARD 11)
|
||||
|
||||
IF(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
||||
target_compile_options(rpmalloc
|
||||
PRIVATE -Wno-unused-variable
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NOT LMMS_BUILD_WIN32)
|
||||
target_compile_definitions(rpmalloc
|
||||
PRIVATE -D_GNU_SOURCE
|
||||
)
|
||||
endif()
|
||||
|
||||
if(MINGW)
|
||||
target_compile_definitions(rpmalloc
|
||||
PRIVATE -D_WIN32_WINNT=0x600
|
||||
)
|
||||
endif()
|
||||
|
||||
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
|
||||
# rpmalloc uses GCC builtin "__builtin_umull_overflow" with ENABLE_VALIDATE_ARGS,
|
||||
# which is only available starting with GCC 5
|
||||
if (CMAKE_C_COMPILER_ID STREQUAL "GNU" AND CMAKE_C_COMPILER_VERSION VERSION_LESS 5)
|
||||
set(ENABLE_VALIDATE_ARGS OFF)
|
||||
else ()
|
||||
set(ENABLE_VALIDATE_ARGS ON)
|
||||
endif()
|
||||
target_compile_definitions(rpmalloc
|
||||
PRIVATE -DENABLE_ASSERTS=1 -DENABLE_VALIDATE_ARGS=${ENABLE_VALIDATE_ARGS}
|
||||
)
|
||||
endif()
|
||||
|
||||
option(LMMS_ENABLE_MALLOC_STATS "Enables statistics for rpmalloc" OFF)
|
||||
|
||||
if (LMMS_ENABLE_MALLOC_STATS)
|
||||
target_compile_definitions(rpmalloc
|
||||
PRIVATE -DENABLE_STATISTICS=1
|
||||
)
|
||||
endif()
|
||||
1
src/3rdparty/rpmalloc/rpmalloc
vendored
1
src/3rdparty/rpmalloc/rpmalloc
vendored
Submodule src/3rdparty/rpmalloc/rpmalloc deleted from 80daac0d53
@@ -186,7 +186,6 @@ SET(LMMS_REQUIRED_LIBS ${LMMS_REQUIRED_LIBS}
|
||||
${SUIL_LIBRARIES}
|
||||
${LILV_LIBRARIES}
|
||||
${FFTW3F_LIBRARIES}
|
||||
rpmalloc
|
||||
SampleRate::samplerate
|
||||
SndFile::sndfile
|
||||
${EXTRA_LIBRARIES}
|
||||
|
||||
@@ -30,7 +30,6 @@
|
||||
|
||||
#include "denormals.h"
|
||||
#include "AudioEngine.h"
|
||||
#include "MemoryManager.h"
|
||||
#include "ThreadableJob.h"
|
||||
|
||||
#if __SSE__
|
||||
@@ -167,7 +166,6 @@ void AudioEngineWorkerThread::startAndWaitForJobs()
|
||||
|
||||
void AudioEngineWorkerThread::run()
|
||||
{
|
||||
MemoryManager::ThreadGuard mmThreadGuard; Q_UNUSED(mmThreadGuard);
|
||||
disable_denormals();
|
||||
|
||||
QMutex m;
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include <cstring>
|
||||
|
||||
#include "MemoryManager.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
@@ -43,7 +42,7 @@ void BufferManager::init( fpp_t fpp )
|
||||
|
||||
sampleFrame * BufferManager::acquire()
|
||||
{
|
||||
return MM_ALLOC<sampleFrame>( s_framesPerPeriod );
|
||||
return new sampleFrame[s_framesPerPeriod];
|
||||
}
|
||||
|
||||
void BufferManager::clear( sampleFrame *ab, const f_cnt_t frames, const f_cnt_t offset )
|
||||
@@ -62,7 +61,7 @@ void BufferManager::clear( surroundSampleFrame * ab, const f_cnt_t frames,
|
||||
|
||||
void BufferManager::release( sampleFrame * buf )
|
||||
{
|
||||
MM_FREE( buf );
|
||||
delete[] buf;
|
||||
}
|
||||
|
||||
} // namespace lmms
|
||||
|
||||
@@ -39,7 +39,6 @@ set(LMMS_SRCS
|
||||
core/LinkedModelGroups.cpp
|
||||
core/LocklessAllocator.cpp
|
||||
core/MemoryHelper.cpp
|
||||
core/MemoryManager.cpp
|
||||
core/MeterModel.cpp
|
||||
core/MicroTimer.cpp
|
||||
core/Microtuner.cpp
|
||||
|
||||
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* MemoryManager.cpp
|
||||
*
|
||||
* Copyright (c) 2017 Lukas W <lukaswhl/at/gmail.com>
|
||||
*
|
||||
* This file is part of LMMS - https://lmms.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
#include "MemoryManager.h"
|
||||
|
||||
#include <QtGlobal>
|
||||
#include "rpmalloc.h"
|
||||
|
||||
namespace lmms
|
||||
{
|
||||
|
||||
|
||||
/// Global static object handling rpmalloc intializing and finalizing
|
||||
struct MemoryManagerGlobalGuard {
|
||||
MemoryManagerGlobalGuard() {
|
||||
rpmalloc_initialize();
|
||||
}
|
||||
~MemoryManagerGlobalGuard() {
|
||||
rpmalloc_finalize();
|
||||
}
|
||||
} static mm_global_guard;
|
||||
|
||||
|
||||
namespace {
|
||||
static thread_local size_t thread_guard_depth;
|
||||
}
|
||||
|
||||
MemoryManager::ThreadGuard::ThreadGuard()
|
||||
{
|
||||
if (thread_guard_depth++ == 0) {
|
||||
rpmalloc_thread_initialize();
|
||||
}
|
||||
}
|
||||
|
||||
MemoryManager::ThreadGuard::~ThreadGuard()
|
||||
{
|
||||
if (--thread_guard_depth == 0) {
|
||||
rpmalloc_thread_finalize(true);
|
||||
}
|
||||
}
|
||||
|
||||
static thread_local MemoryManager::ThreadGuard local_mm_thread_guard{};
|
||||
|
||||
void* MemoryManager::alloc(size_t size)
|
||||
{
|
||||
// Reference local thread guard to ensure it is initialized.
|
||||
// Compilers may optimize the instance away otherwise.
|
||||
Q_UNUSED(&local_mm_thread_guard);
|
||||
Q_ASSERT_X(rpmalloc_is_thread_initialized(), "MemoryManager::alloc", "Thread not initialized");
|
||||
return rpmalloc(size);
|
||||
}
|
||||
|
||||
|
||||
void MemoryManager::free(void * ptr)
|
||||
{
|
||||
Q_UNUSED(&local_mm_thread_guard);
|
||||
Q_ASSERT_X(rpmalloc_is_thread_initialized(), "MemoryManager::free", "Thread not initialized");
|
||||
return rpfree(ptr);
|
||||
}
|
||||
|
||||
|
||||
} // namespace lmms
|
||||
@@ -610,9 +610,9 @@ int NotePlayHandleManager::s_size;
|
||||
|
||||
void NotePlayHandleManager::init()
|
||||
{
|
||||
s_available = MM_ALLOC<NotePlayHandle*>( INITIAL_NPH_CACHE );
|
||||
s_available = new NotePlayHandle*[INITIAL_NPH_CACHE];
|
||||
|
||||
auto n = MM_ALLOC<NotePlayHandle>(INITIAL_NPH_CACHE);
|
||||
auto n = static_cast<NotePlayHandle *>(std::malloc(sizeof(NotePlayHandle) * INITIAL_NPH_CACHE));
|
||||
|
||||
for( int i=0; i < INITIAL_NPH_CACHE; ++i )
|
||||
{
|
||||
@@ -655,11 +655,11 @@ void NotePlayHandleManager::release( NotePlayHandle * nph )
|
||||
void NotePlayHandleManager::extend( int c )
|
||||
{
|
||||
s_size += c;
|
||||
auto tmp = MM_ALLOC<NotePlayHandle*>(s_size);
|
||||
MM_FREE( s_available );
|
||||
auto tmp = new NotePlayHandle*[s_size];
|
||||
delete[] s_available;
|
||||
s_available = tmp;
|
||||
|
||||
auto n = MM_ALLOC<NotePlayHandle>(c);
|
||||
auto n = static_cast<NotePlayHandle *>(std::malloc(sizeof(NotePlayHandle) * c));
|
||||
|
||||
for( int i=0; i < c; ++i )
|
||||
{
|
||||
@@ -670,7 +670,7 @@ void NotePlayHandleManager::extend( int c )
|
||||
|
||||
void NotePlayHandleManager::free()
|
||||
{
|
||||
MM_FREE(s_available);
|
||||
delete[] s_available;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -159,7 +159,6 @@ void ProjectRenderer::startProcessing()
|
||||
|
||||
void ProjectRenderer::run()
|
||||
{
|
||||
MemoryManager::ThreadGuard mmThreadGuard; Q_UNUSED(mmThreadGuard);
|
||||
#if 0
|
||||
#if defined(LMMS_BUILD_LINUX) || defined(LMMS_BUILD_FREEBSD)
|
||||
#ifdef LMMS_HAVE_SCHED_H
|
||||
|
||||
Reference in New Issue
Block a user