Commit 1b49e27e authored by Alejandro Homs Puron's avatar Alejandro Homs Puron

Merge branch...

Merge branch '92-memutils-softbufferallocmgr-fix-issues-when-allocating-more-hw-buffers-2' into 'master'

Resolve "MemUtils/SoftBufferAllocMgr: Fix issues when allocating more HW buffers"

Closes #92

See merge request !124
parents 21404faf 50cde7c9
Pipeline #10270 passed with stages
in 12 minutes and 58 seconds
......@@ -374,9 +374,7 @@ endif()
if(LIMA_ENABLE_TESTS)
enable_testing()
add_subdirectory(control/test)
if (NOT WIN32)
add_subdirectory(common/test)
endif()
add_subdirectory(common/test)
endif()
#--------------------------------------------------------------------------------
......
......@@ -53,7 +53,7 @@ class LIMACORE_API MemBuffer
MemBuffer& operator=(const MemBuffer&);
// MemBuffer are move-constructible or move-assignable.
MemBuffer(MemBuffer&&) = default;
MemBuffer(MemBuffer&&);
MemBuffer& operator=(MemBuffer&&) = default;
#ifdef LIMA_USE_NUMA
......
......@@ -118,7 +118,8 @@ void MemBuffer::Allocator::alloc(MemBuffer& buffer, int& size)
void *ptr;
#ifdef __unix
if (useMmap(size)) {
ptr = allocMmap(size);
int real_size = size;
ptr = allocMmap(real_size);
} else {
int ret = posix_memalign(&ptr, Alignment, size);
if (ret != 0)
......@@ -182,10 +183,14 @@ void MemBuffer::Allocator::release(MemBuffer& buffer)
int size = buffer.getSize();
#ifdef __unix
if (useMmap(size))
munmap(ptr, size);
else
if (useMmap(size)) {
int real_size = getPageAlignedSize(size);
if (munmap(ptr, real_size) != 0)
throw LIMA_COM_EXC(Error, "Error in munmap: ")
<< strerror(errno);
} else {
free(ptr);
}
#else
_aligned_free(ptr);
#endif
......@@ -206,6 +211,7 @@ int MemBuffer::Allocator::getPageAlignedSize(int size)
#ifdef __unix
bool MemBuffer::Allocator::useMmap(int size)
{
// Use MMap if size is greater than 128KB
return size >= 128 * 1024;
}
......@@ -248,6 +254,18 @@ MemBuffer::MemBuffer(const MemBuffer& buffer)
deepCopy(buffer);
}
MemBuffer::MemBuffer(MemBuffer&& rhs)
{
// Stealing buffer ressource
m_ptr = std::move(rhs.m_ptr);
m_size = std::move(rhs.m_size);
m_allocator = std::move(rhs.m_allocator);
// Repare rhs (we don't it to be deallocated twice)
rhs.m_ptr = nullptr;
rhs.m_size = 0;
}
MemBuffer::~MemBuffer()
{
release();
......
......@@ -20,6 +20,9 @@
# along with this program; if not, see <http://www.gnu.org/licenses/>.
############################################################################
set(test_src testregex)
set(test_src test_membuffer)
if (NOT WIN32)
list(APPEND test_src test_regex)
endif()
limatools_run_camera_tests("${test_src}" ${NAME})
//###########################################################################
// This file is part of LImA, a Library for Image Acquisition
//
// Copyright (C) : 2009-2011
// European Synchrotron Radiation Facility
// BP 220, Grenoble 38043
// FRANCE
//
// This 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 3 of the License, or
// (at your option) any later version.
//
// This software 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; if not, see <http://www.gnu.org/licenses/>.
//###########################################################################
#include <cassert>
#include <cstdlib>
#include <iostream>
#include <utility>
#include "lima/MemUtils.h"
using namespace lima;
void test_empty()
{
//Default construction
MemBuffer b;
assert(b.getSize() == 0);
//Copy construction
MemBuffer c(b);
assert(b.getSize() == 0);
//Copy assignement
MemBuffer d = b;
//Move construction
MemBuffer e(std::move(b));
//Move assignement
MemBuffer f = std::move(b);
}
void test_alloc()
{
//Default construction
MemBuffer b(1);
assert(b.getSize() == 1);
//Copy construction
MemBuffer c(b);
assert(c.getSize() == 1);
assert(c.getConstPtr() != b.getConstPtr());
//Copy assignement
MemBuffer d = b;
assert(d.getSize() == 1);
assert(d.getConstPtr() != b.getConstPtr());
//Move construction (from lvalue)
const void *ptr = b.getConstPtr();
MemBuffer e(std::move(b));
assert(e.getSize() == 1);
assert(e.getConstPtr() == ptr);
assert(b.getConstPtr() == nullptr);
assert(b.getSize() == 0);
//Move assignement (from lvalue)
MemBuffer f = std::move(e);
assert(f.getSize() == 1);
assert(f.getConstPtr() == ptr);
assert(e.getConstPtr() == nullptr);
assert(e.getSize() == 0);
//Move construction (from rvalue)
MemBuffer g(MemBuffer(1));
assert(g.getSize() == 1);
//Move assignement (from rvalue)
MemBuffer h = MemBuffer(1);
assert(g.getSize() == 1);
}
int main(int argc, char *argv[])
{
try {
test_empty();
test_alloc();
} catch (Exception e) {
std::cerr << "LIMA Exception: " << e << std::endl;
}
return 0;
}
......@@ -127,7 +127,7 @@ void SoftBufferAllocMgr::allocBuffers(int nb_buffers,
if (to_alloc > 0) {
bl.resize(nb_buffers);
DEB_TRACE() << "Allocating " << to_alloc << " buffers";
for (int i = 0; i < nb_buffers; i++) {
for (int i = curr_nb_buffers; i < nb_buffers; i++) {
#ifdef LIMA_USE_NUMA
if (m_cpu_mask)
bl[i].setCPUAffinityMask(m_cpu_mask);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment