-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
shared_memory_allocator.cpp
40 lines (28 loc) · 1.31 KB
/
shared_memory_allocator.cpp
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
#include "engine/datafacade/shared_memory_allocator.hpp"
#include "storage/serialization.hpp"
#include "util/log.hpp"
#include "boost/assert.hpp"
namespace osrm::engine::datafacade
{
SharedMemoryAllocator::SharedMemoryAllocator(
const std::vector<storage::SharedRegionRegister::ShmKey> &shm_keys)
{
std::vector<storage::SharedDataIndex::AllocatedRegion> regions;
for (const auto shm_key : shm_keys)
{
util::Log(logDEBUG) << "Loading new data for region " << (int)shm_key;
BOOST_ASSERT(storage::SharedMemory::RegionExists(shm_key));
auto mem = storage::makeSharedMemory(shm_key);
storage::io::BufferReader reader(reinterpret_cast<char *>(mem->Ptr()), mem->Size());
std::unique_ptr<storage::BaseDataLayout> layout =
std::make_unique<storage::ContiguousDataLayout>();
storage::serialization::read(reader, *layout);
auto layout_size = reader.GetPosition();
regions.push_back({reinterpret_cast<char *>(mem->Ptr()) + layout_size, std::move(layout)});
memory_regions.push_back(std::move(mem));
}
index = storage::SharedDataIndex{std::move(regions)};
}
SharedMemoryAllocator::~SharedMemoryAllocator() {}
const storage::SharedDataIndex &SharedMemoryAllocator::GetIndex() { return index; }
} // namespace osrm::engine::datafacade