blob: 40bbc3fbf8c97a40d66fc9e8989a65d8f0f7cb02 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
// Copyright (C) by Josh Blum. See LICENSE.txt for licensing information.
#include <gras/sbuffer.hpp>
#include "alloc_on_node.hpp"
#include <boost/bind.hpp>
using namespace gras;
SBufferConfig::SBufferConfig(void)
{
memory = NULL;
length = 0;
affinity = -1;
user_index = ~0;
}
static void numa_mem_deleter(SBuffer &buff)
{
FreeOnNode(buff.get_actual_memory(), buff.get_actual_length());
}
static void default_allocator_deleter(SBuffer &, char *m)
{
delete [] m;
}
static void default_allocator(SBufferConfig &config)
{
if (config.affinity == -1)
{
char *m = new char[config.length + GRAS_MAX_ALIGNMENT - 1];
size_t x = size_t(m) + GRAS_MAX_ALIGNMENT - 1;
x -= x % GRAS_MAX_ALIGNMENT;
config.memory = (void *)x;
config.deleter = boost::bind(&default_allocator_deleter, _1, m);
}
else
{
config.memory = AllocOnNode(config.affinity, config.length);
config.deleter = boost::bind(&numa_mem_deleter, _1);
//deal with numa failue case //TODO print warning message
if (config.memory == NULL)
{
config.affinity = -1;
default_allocator(config);
}
}
}
SBuffer::SBuffer(const SBufferConfig &config):
offset(0),
length(0)
{
this->reset(new SBufferImpl(config));
if (config.memory == NULL)
{
default_allocator((*this)->config);
}
this->length = this->get_actual_length();
}
|