Prepare utils/memory for switching to libstdc++-9
Reviewers: mtomic, mferencevic Reviewed By: mtomic Subscribers: pullbot Differential Revision: https://phabricator.memgraph.io/D2246
This commit is contained in:
parent
124a44731d
commit
3a95a3c29d
@ -15,7 +15,11 @@
|
|||||||
// Although <memory_resource> is in C++17, gcc libstdc++ still needs to
|
// Although <memory_resource> is in C++17, gcc libstdc++ still needs to
|
||||||
// implement it fully. It should be available in the next major release
|
// implement it fully. It should be available in the next major release
|
||||||
// version, i.e. gcc 9.x.
|
// version, i.e. gcc 9.x.
|
||||||
|
#if _GLIBCXX_RELEASE < 9
|
||||||
#include <experimental/memory_resource>
|
#include <experimental/memory_resource>
|
||||||
|
#else
|
||||||
|
#include <memory_resource>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "utils/math.hpp"
|
#include "utils/math.hpp"
|
||||||
#include "utils/spin_lock.hpp"
|
#include "utils/spin_lock.hpp"
|
||||||
@ -264,9 +268,13 @@ using AVector = std::vector<T, Allocator<T>>;
|
|||||||
/// Wraps std::pmr::memory_resource for use with out MemoryResource
|
/// Wraps std::pmr::memory_resource for use with out MemoryResource
|
||||||
class StdMemoryResource final : public MemoryResource {
|
class StdMemoryResource final : public MemoryResource {
|
||||||
public:
|
public:
|
||||||
/// Implicitly convert std::pmr::memory_resource to StdMemoryResource
|
#if _GLIBCXX_RELEASE < 9
|
||||||
StdMemoryResource(std::experimental::pmr::memory_resource *memory)
|
StdMemoryResource(std::experimental::pmr::memory_resource *memory)
|
||||||
: memory_(memory) {}
|
: memory_(memory) {}
|
||||||
|
#else
|
||||||
|
/// Implicitly convert std::pmr::memory_resource to StdMemoryResource
|
||||||
|
StdMemoryResource(std::pmr::memory_resource *memory) : memory_(memory) {}
|
||||||
|
#endif
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void *DoAllocate(size_t bytes, size_t alignment) override {
|
void *DoAllocate(size_t bytes, size_t alignment) override {
|
||||||
@ -292,12 +300,20 @@ class StdMemoryResource final : public MemoryResource {
|
|||||||
return *memory_ == *other_std->memory_;
|
return *memory_ == *other_std->memory_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if _GLIBCXX_RELEASE < 9
|
||||||
std::experimental::pmr::memory_resource *memory_;
|
std::experimental::pmr::memory_resource *memory_;
|
||||||
|
#else
|
||||||
|
std::pmr::memory_resource *memory_;
|
||||||
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
inline MemoryResource *NewDeleteResource() noexcept {
|
inline MemoryResource *NewDeleteResource() noexcept {
|
||||||
|
#if _GLIBCXX_RELEASE < 9
|
||||||
static StdMemoryResource memory(
|
static StdMemoryResource memory(
|
||||||
std::experimental::pmr::new_delete_resource());
|
std::experimental::pmr::new_delete_resource());
|
||||||
|
#else
|
||||||
|
static StdMemoryResource memory(std::pmr::new_delete_resource());
|
||||||
|
#endif
|
||||||
return &memory;
|
return &memory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user