21 class LockedMemoryBase {
22 IAllocator *_allocator =
nullptr;
23 void *_handle =
nullptr;
24 mutable T *_locked =
nullptr;
25 LockOp _lockFlag = LOCK_FOR_WRITE;
42 LockedMemoryBase(IAllocator *ptr,
void *handle, LockOp lockFlag,
size_t offsetInBytes)
43 : _allocator(ptr), _handle(handle), _lockFlag(lockFlag), _offset(offsetInBytes) {
50 LockedMemoryBase(LockedMemoryBase &&that)
51 : _allocator(that._allocator), _handle(that._handle), _lockFlag(that._lockFlag),
52 _offset(that._offset) {
53 that._locked =
nullptr;
59 virtual ~LockedMemoryBase() {
60 if (_locked !=
nullptr) {
61 _allocator->unlock(_handle);
71 bool isEqualTo(
const T *pointer)
const {
72 if (pointer ==
nullptr &&
73 (_allocator ==
nullptr || _handle ==
nullptr)) {
76 return dereference() == pointer;
84 virtual T *dereference()
const {
85 if (_locked !=
nullptr)
return _locked;
87 if (_allocator ==
nullptr) {
91 if (_handle ==
nullptr) {
95 uint8_t *pBytes =
reinterpret_cast<uint8_t *
>(_allocator->lock(_handle, _lockFlag));
97 return _locked =
reinterpret_cast<T *
> (pBytes + _offset);
108 using base = details::LockedMemoryBase<T>;
118 : base(ptr, handle, LOCK_FOR_WRITE, offsetInBytes) {
133 : base(std::move(that)) {
134 base::_offset = offset;
148 return base::dereference();
156 operator const T *()
const {
157 return base::dereference();
166 return base::isEqualTo(pointer);
174 return lm.operator==(pointer);
183 template<class S, typename = std::enable_if<std::is_pointer<S>::value>>
185 return reinterpret_cast<S
>(base::dereference());
194 template<class S, typename = std::enable_if<std::is_pointer<S>::value>>
196 return reinterpret_cast<S
>(base::dereference());
205 using base = details::LockedMemoryBase<void>;
215 : base(ptr, handle, LOCK_FOR_WRITE, offsetInBytes) {
230 : base(std::move(that)) {
231 base::_offset = offset;
247 return reinterpret_cast<S *
>(base::dereference());
256 return base::isEqualTo(pointer);
264 return lm.operator==(pointer);
273 template<class S, typename = std::enable_if<std::is_pointer<S>::value>>
275 return reinterpret_cast<S
>(dereference());
284 template<class S, typename = std::enable_if<std::is_pointer<S>::value>>
286 return reinterpret_cast<S
>(dereference());
296 using base = details::LockedMemoryBase<T>;
306 : base(ptr, handle, LOCK_FOR_READ, offset) {
321 : base(std::move(that)) {
322 base::_offset = offset;
335 operator const T *()
const {
336 return base::dereference();
345 return base::isEqualTo(pointer);
353 return lm.operator==(pointer);
362 template<class S, typename = std::enable_if<std::is_pointer<S>::value && std::is_const<S>::value>>
364 return reinterpret_cast<S
>(base::dereference());
LockedMemory(IAllocator *ptr, void *handle, size_t offsetInBytes=0)
A constructor.
Definition: ie_locked_memory.hpp:117
This class represents locked memory for read/write memory.
Definition: ie_locked_memory.hpp:107
Definition: ie_argmax_layer.hpp:11
friend bool operator==(const T *pointer, const LockedMemory< const T > &lm)
Compares the object with the one stored in the memory.
Definition: ie_locked_memory.hpp:352
bool operator==(const T *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:343
friend bool operator==(const T *pointer, const LockedMemory< T > &lm)
Compares the object with the one stored in the memory.
Definition: ie_locked_memory.hpp:173
bool operator==(const void *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:254
S as()
Casts stored object to any provided type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:184
LockedMemory(LockedMemory< void > &&that, size_t offset)
A default copy constructor that accepts rvalue Also sets the offset value for the new memory object...
Definition: ie_locked_memory.hpp:229
This class is for <void*> data and allows casting to any pointers.
Definition: ie_locked_memory.hpp:204
S as() const
Casts stored object to any given type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:363
This class is for read-only segments.
Definition: ie_locked_memory.hpp:295
LockedMemory(IAllocator *ptr, void *handle, size_t offset)
A constructor.
Definition: ie_locked_memory.hpp:305
const S as() const
Casts stored object to any given type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:285
A header file that provides Allocator interface.
S as()
Casts stored object to any given type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:274
LockedMemory(IAllocator *ptr, void *handle, size_t offsetInBytes)
A constructor.
Definition: ie_locked_memory.hpp:214
bool operator==(const T *pointer) const
Compares stored object with the given one.
Definition: ie_locked_memory.hpp:164
LockOp
Allocator handle mapping type.
Definition: ie_allocator.hpp:19
friend bool operator==(const void *pointer, const LockedMemory< void > &lm)
Compares the object with the one stored in the memory.
Definition: ie_locked_memory.hpp:263
Allocator concept to be used for memory management and is used as part of the Blob.
Definition: ie_allocator.hpp:27
LockedMemory(LockedMemory< T > &&that, size_t offset)
A default copy constructor that accepts rvalue Also sets the offset value for the new memory object...
Definition: ie_locked_memory.hpp:132
const S as() const
Casts stored object to any provided type. Uses reinterpret_cast.
Definition: ie_locked_memory.hpp:195
LockedMemory(LockedMemory< const T > &&that, size_t offset)
A default copy constructor that accepts rvalue. Also sets the offset value for the new memory object...
Definition: ie_locked_memory.hpp:320