Skip to content
Snippets Groups Projects
Commit f9f7ff66 authored by Nikita Pettik's avatar Nikita Pettik Committed by Nikita Pettik
Browse files

memtx: introduce interfaces for MemtxAllocator

That includes:
 - foreach_memtx_allocator() - for each basic allocator (Small and Sys
   so far) we declare corresponding MemtxAllocator. So to iterate over
   all allocators and invoke same function we are going to use this
   helper;
 - memtx_allocators_init() - invoke ::create() of each Allocator and
   corresponding MemtxAllocator;
 - memtx_allocators_destroy() - invoke ::destroy() of each Allocator
   and corresponding MemtxAllocator;
 - memtx_allocators_set_mode() - set given delayed free mode for each
   MemtxAllocator.

Follow-up #5419
parent ce2dcad5
No related branches found
No related tags found
No related merge requests found
......@@ -115,6 +115,7 @@ target_link_libraries(xlog core box_error crc32 ${ZSTD_LIBRARIES})
add_library(box STATIC
allocator.cc
memtx_allocator.cc
msgpack.c
iproto.cc
xrow_io.cc
......
/*
* Copyright 2010-2021, Tarantool AUTHORS, please see AUTHORS file.
*
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the following
* conditions are met:
*
* 1. Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY <COPYRIGHT HOLDER> ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* <COPYRIGHT HOLDER> OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
* THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include "memtx_allocator.h"
struct memtx_allocator_set_mode {
template<typename Allocator, typename...Arg>
void
invoke(Arg&&...mode)
{
Allocator::set_mode(mode...);
}
};
void
memtx_allocators_init(struct memtx_engine *memtx,
struct allocator_settings *settings)
{
foreach_allocator<allocator_create,
struct allocator_settings *&>(settings);
foreach_memtx_allocator<allocator_create,
enum memtx_engine_free_mode &>(memtx->free_mode);
}
void
memtx_allocators_set_mode(enum memtx_engine_free_mode mode)
{
foreach_memtx_allocator<memtx_allocator_set_mode,
enum memtx_engine_free_mode &>(mode);
}
void
memtx_allocators_destroy()
{
foreach_memtx_allocator<allocator_destroy>();
foreach_allocator<allocator_destroy>();
}
......@@ -118,3 +118,25 @@ struct lifo MemtxAllocator<Allocator>::lifo;
template<class Allocator>
enum memtx_engine_free_mode MemtxAllocator<Allocator>::mode;
void
memtx_allocators_init(struct memtx_engine *memtx,
struct allocator_settings *settings);
void
memtx_allocators_set_mode(enum memtx_engine_free_mode mode);
void
memtx_allocators_destroy();
using memtx_allocators = std::tuple<MemtxAllocator<SmallAlloc>,
MemtxAllocator<SysAlloc>>;
template<class F, class...Arg>
static void
foreach_memtx_allocator(Arg&&...arg)
{
F f;
foreach_allocator_internal((memtx_allocators *) nullptr, f,
std::forward<Arg>(arg)...);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment