Thread safe smart pointer for raw memory blocks.
More...
Thread safe smart pointer for raw memory blocks.
Definition at line 21 of file asyncmemoryblock.h.
◆ Alloc()
Allocates new memory for the MemoryBlock *.
- Parameters
-
- Return values
-
ERR_NOERROR | no Error |
ERR_RESOURCE_IN_USE | memory already allocated or assigned |
ERR_MEMORY | no memory available |
◆ Assign()
Assigns memory to the MemoryBlock object which has already been allocated.
- Parameters
-
pMem | [in] memory pointer |
nSize | [in] memory size |
- Return values
-
ERR_NOERROR | no Error |
ERR_RESOURCE_IN_USE | memory already allocated or assigned |
- This method is real-time safe.\nSee @ref page_real_time_safe.\n
◆ Compare()
Compares size and content with another MemoryBlock.
- Parameters
-
oSrc | [in] Source MemoryBlock to be copied |
- Return values
-
◆ Copy()
Copies the content of the source MemoryBlock.
The size of the destination is adjusted to the source.
- Parameters
-
oSrc | [in] Source MemoryBlock to be copied |
- Return values
-
STATUS_OK | no error |
ERR_MEMORY | memory error |
◆ Free()
Lock MemoryBlock and free memory is allocated and not assigned *.
- Return values
-
STATUS_OK | no Error |
ERR_MEMORY | no memory allocated or assigned |
◆ GetSize()
Get size of MemoryBlock.
- Returns
- Size of MemoryBlock
- This method is real-time safe.\nSee @ref page_real_time_safe.\n
◆ ReadLock()
Try to lock memory for read access.
Multiple read access is allowed. Wait (send thread to sleep) if MemoryBlock is locked by a write access. If parameter bWait == tFalse this method returns STATUS_ERROR without waiting if no immediate access is possible. Memory pointer of the Block is returned in the parameter ppMem. Calling ReadLock after WriteLock on the same thread will not block. Only calls from different threads will block.
- Parameters
-
bWait | [in] tTrue: wait if access is locked |
ppMem | [out] Memory pointer of this MemoryBlock |
- Return values
-
STATUS_OK | no Error |
ERR_POINTER | ppMem is nullptr |
ERR_UNEXPECTED | no memory is allocated |
ERR_RESOURCE_IN_USE | if memory is locked and bWait is tFalse |
◆ Unlock()
Unlock MemoryBlock.
If currently write access: allow read and write access. If currently read access: decrement reader counter and allow write access if no more reader active.
- Return values
-
STATUS_OK | no Error |
ERR_UNEXPECTED | no access active or no memory allocated |
◆ WaitNewData()
Wait for the NewDataEvent which is set by unlocking a write access.
- Parameters
-
nTimeout | [in] Timeout, default = -1 (INFINITE) |
- Return values
-
STATUS_OK | no error |
ERR_TIMEOUT | wait error / timeout |
◆ WriteLock()
Try to lock memory for write access.
Only one writer and no reader is allowed. Wait (send thread to sleep) if other write or read access is active. If parameter bWait == tFalse this method returns STATUS_ERROR without waiting if no immediate access is possible. Memory pointer of the MemoryBlock is returned in the parameter ppMem. Calling WriteLock will not block if it is called repeatedly from the same thread. Only calls from different threads will result in a block.
- Parameters
-
bWait | [in] tTrue: wait if access is locked |
ppMem | [out] Memory pointer of this MemoryBlock |
- Return values
-
STATUS_OK | no Error |
ERR_POINTER | ppMem is nullptr |
ERR_UNEXPECTED | no memory is allocated |
ERR_RESOURCE_IN_USE | if memory is locked and bWait is tFalse |