From ba2629456fb9873ef3bb35e24ae52483bcd8abe8 Mon Sep 17 00:00:00 2001 From: Michael Krasnyk Date: Thu, 17 Nov 2016 14:36:03 +0100 Subject: [PATCH] Added a copy of std::align due to missing implementation in gcc < 5 References: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57350 --- include/storage/shared_datatype.hpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/include/storage/shared_datatype.hpp b/include/storage/shared_datatype.hpp index e474803a1..f47ac73c2 100644 --- a/include/storage/shared_datatype.hpp +++ b/include/storage/shared_datatype.hpp @@ -6,7 +6,6 @@ #include #include -#include namespace osrm { @@ -131,20 +130,29 @@ struct DataLayout return result; } + // \brief Fit aligned storage in buffer. + // Interface Similar to [ptr.align] but omits space computation. + // The method can be removed and changed directly to an std::align + // function call after dropping gcc < 5 support. + inline void* align(std::size_t align, std::size_t , void*& ptr) const noexcept + { + const auto intptr = reinterpret_cast(ptr); + const auto aligned = (intptr - 1u + align) & -align; + return ptr = reinterpret_cast(aligned); + } + inline void *GetAlignedBlockPtr(void *ptr, BlockID bid) const { for (auto i = 0; i < bid; i++) { ptr = static_cast(ptr) + sizeof(CANARY); - std::size_t space = 2 * entry_align[i] + entry_size[i]; - ptr = std::align(entry_align[i], entry_size[i], ptr, space); + ptr = align(entry_align[i], entry_size[i], ptr); ptr = static_cast(ptr) + GetBlockSize((BlockID)i); ptr = static_cast(ptr) + sizeof(CANARY); } ptr = static_cast(ptr) + sizeof(CANARY); - std::size_t space = 2 * entry_align[bid] + entry_size[bid]; - ptr = std::align(entry_align[bid], entry_size[bid], ptr, space); + ptr = align(entry_align[bid], entry_size[bid], ptr); return ptr; }