vecmem 1.14.0
Loading...
Searching...
No Matches
synchronized_memory_resource.hpp
1/* VecMem project, part of the ACTS project (R&D line)
2 *
3 * (c) 2023 CERN for the benefit of the ACTS project
4 *
5 * Mozilla Public License Version 2.0
6 */
7#pragma once
8
9// Local include(s).
10#include "vecmem/memory/memory_resource.hpp"
11#include "vecmem/vecmem_core_export.hpp"
12
13// System include(s).
14#include <functional>
15#include <mutex>
16
17namespace vecmem {
18
26class synchronized_memory_resource final : public memory_resource {
27
28public:
31 synchronized_memory_resource(memory_resource& upstream);
38
42
50
51private:
54
57 virtual void* do_allocate(std::size_t, std::size_t) override final;
60 virtual void do_deallocate(void* p, std::size_t,
61 std::size_t) override final;
64 virtual bool do_is_equal(
65 const memory_resource& other) const noexcept override final;
66
68
70 std::reference_wrapper<memory_resource> m_upstream;
72 std::mutex m_mutex;
73
74}; // class synchronized_memory_resource
75
76} // namespace vecmem
A memory resource that synchronizes the operations of an upstream resource.
Definition synchronized_memory_resource.hpp:26
virtual VECMEM_CORE_EXPORT void do_deallocate(void *p, std::size_t, std::size_t) override final
De-allocate a previously allocated memory block.
Definition synchronized_memory_resource.cpp:52
virtual VECMEM_CORE_EXPORT void * do_allocate(std::size_t, std::size_t) override final
Allocate memory with one of the underlying resources.
Definition synchronized_memory_resource.cpp:45
VECMEM_CORE_EXPORT synchronized_memory_resource & operator=(synchronized_memory_resource &&rhs)
Move assignment operator.
Definition synchronized_memory_resource.cpp:27
virtual VECMEM_CORE_EXPORT bool do_is_equal(const memory_resource &other) const noexcept override final
Compare the equality of *this memory resource with another.
Definition synchronized_memory_resource.cpp:59
virtual VECMEM_CORE_EXPORT ~synchronized_memory_resource()
Destructor.
Main namespace for the vecmem classes/functions.
Definition atomic_ref.hpp:16
std::vector< T, vecmem::polymorphic_allocator< T > > vector
Alias type for vectors with our polymorphic allocator.
Definition vector.hpp:35