Project
Loading...
Searching...
No Matches
ExternalAllocator.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
15
16#ifndef TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
17#define TRACKINGITSU_INCLUDE_EXTERNALALLOCATOR_H_
18
19#include <memory_resource>
20#include "GPUO2ExternalUser.h"
22
23namespace o2::its
24{
25
27{
28 using Type = std::underlying_type_t<o2::gpu::GPUMemoryResource::MemoryType>;
29
30 public:
31 virtual void deallocate(char*, size_t) = 0;
32 virtual void* allocate(size_t) = 0;
33 void* allocate(size_t s, Type type)
34 {
35 auto old = mType;
36 mType = type;
37 void* p = allocate(s);
38 mType = old;
39 return p;
40 }
45 virtual void pushTagOnStack(uint64_t) = 0;
46 virtual void popTagOffStack(uint64_t) = 0;
47
48 void setType(Type t) noexcept { mType = t; }
49 Type getType() const noexcept { return mType; }
50
51 protected:
52 Type mType;
53};
54
56{
57 public:
58 explicit ExternalAllocatorAdaptor(ExternalAllocator* alloc) : mAlloc(alloc) {}
59
60 protected:
61 void* do_allocate(size_t bytes, size_t alignment) override
62 {
64 if (!p) {
65 throw std::bad_alloc();
66 }
67 return p;
68 }
69
70 void do_deallocate(void* p, size_t bytes, size_t) override
71 {
72 mAlloc->deallocate(static_cast<char*>(p), bytes);
73 }
74
75 bool do_is_equal(const std::pmr::memory_resource& other) const noexcept override
76 {
77 return this == &other;
78 }
79
80 private:
81 ExternalAllocator* mAlloc;
82};
83
84} // namespace o2::its
85
86#endif
void * do_allocate(size_t bytes, size_t alignment) override
ExternalAllocatorAdaptor(ExternalAllocator *alloc)
void do_deallocate(void *p, size_t bytes, size_t) override
bool do_is_equal(const std::pmr::memory_resource &other) const noexcept override
virtual void pushTagOnStack(uint64_t)=0
virtual void deallocate(char *, size_t)=0
void * allocate(size_t s, Type type)
void setType(Type t) noexcept
Type getType() const noexcept
virtual void * allocate(size_t)=0
virtual void popTagOffStack(uint64_t)=0
GLint GLint GLsizei GLint GLenum GLenum type
Definition glcorearb.h:275
VectorOfTObjectPtrs other