11#include <promeki/config.h>
12#if PROMEKI_ENABLE_CORE
25PROMEKI_NAMESPACE_BEGIN
82 PROMEKI_SHARED_BASE(BufferImpl)
84 BufferImpl() =
default;
85 virtual ~BufferImpl() =
default;
87 BufferImpl(
const BufferImpl &) =
default;
88 BufferImpl &operator=(
const BufferImpl &) =
default;
93 virtual MemSpace memSpace()
const = 0;
96 virtual size_t allocSize()
const = 0;
99 virtual size_t align()
const = 0;
107 bool isMapped(MemDomain domain)
const {
return mapRefcount(domain.id()) > 0; }
118 virtual void *mappedHostData()
const = 0;
134 virtual BufferRequest mapAcquire(MemDomain domain, MapFlags flags) = 0;
145 virtual BufferRequest mapRelease(MemDomain domain) = 0;
157 virtual Error fill(
char value,
size_t offset,
size_t bytes) = 0;
170 virtual Error copyFromHost(
const void *src,
size_t bytes,
size_t offset) = 0;
175 size_t logicalSize()
const {
return _logicalSize; }
189 void setLogicalSize(
size_t s)
const { _logicalSize = s; }
192 size_t shift()
const {
return _shift; }
200 void setShift(
size_t s) {
216 virtual bool canClone()
const {
return true; }
242 virtual Error seal()
const {
return Error::Ok; }
262 virtual size_t residentBytes()
const {
return allocSize(); }
275 virtual bool isCowBacked()
const {
return false; }
285 int incrementMapRefcount(MemDomain::ID domain) {
286 Mutex::Locker lock(_mapMutex);
287 auto it = _mapRefcounts.find(domain);
288 if (it == _mapRefcounts.end()) {
289 _mapRefcounts.insert(domain, 1);
302 int decrementMapRefcount(MemDomain::ID domain) {
303 Mutex::Locker lock(_mapMutex);
304 auto it = _mapRefcounts.find(domain);
305 if (it == _mapRefcounts.end())
return -1;
306 if (it->second == 0)
return -1;
315 int mapRefcount(MemDomain::ID domain)
const {
316 Mutex::Locker lock(_mapMutex);
317 auto it = _mapRefcounts.find(domain);
318 return (it == _mapRefcounts.end()) ? 0 : it->second;
331 void seedMapRefcount(MemDomain::ID domain,
int count) { _mapRefcounts.insert(domain, count); }
333 mutable size_t _logicalSize = 0;
337 mutable Mutex _mapMutex;
338 Map<MemDomain::ID, int> _mapRefcounts;