ADTF  v2.14.3
cAsyncMemoryBlock Class Reference

Thread safe smart pointer for raw memory blocks. More...

Public Member Functions

 cAsyncMemoryBlock ()
 Default constructor.
 
virtual ~cAsyncMemoryBlock ()
 Destructor.
 
tResult Alloc (tInt nSize)
 Allocates new memory for the MemoryBlock *. More...
 
tResult Assign (void *pMem, tInt nSize)
 Assigns memory to the MemoryBlock object which has already been allocated. More...
 
tResult Free ()
 Lock MemoryBlock and free memory is allocated and not assigned *. More...
 
tResult ReadLock (void **ppMem, const tBool bWait=tTrue)
 Try to lock memory for read access. More...
 
tResult WriteLock (void **ppMem, const tBool bWait=tTrue)
 Try to lock memory for write access. More...
 
tResult Unlock (void)
 Unlock MemoryBlock. More...
 
tResult Copy (cAsyncMemoryBlock &oSrc)
 Copies the content of the source MemoryBlock. More...
 
tInt Compare (cAsyncMemoryBlock &oSrc)
 Compares size and content with another MemoryBlock. More...
 
tInt GetSize ()
 Get size of MemoryBlock. More...
 
tResult WaitNewData (tInt nTimeout=-1)
 Wait for the NewDataEvent which is set by unlocking a write access. More...
 

Detailed Description

Thread safe smart pointer for raw memory blocks.

Definition at line 26 of file asyncmemoryblock.h.

Member Function Documentation

tResult Alloc ( tInt  nSize)

Allocates new memory for the MemoryBlock *.

Parameters
nSize[in] memory size
Return values
ERR_NOERRORno Error
ERR_RESSOURCE_IN_USEmemory already allocated or assigned
ERR_MEMORYno memory available
tResult Assign ( void *  pMem,
tInt  nSize 
)

Assigns memory to the MemoryBlock object which has already been allocated.

Parameters
pMem[in] memory pointer
nSize[in] memory size
Return values
ERR_NOERRORno Error
ERR_RESSOURCE_IN_USEmemory already allocated or assigned
This method is real-time safe.
See The ADTF Real-Time Extension.
tInt Compare ( cAsyncMemoryBlock oSrc)

Compares size and content with another MemoryBlock.

Parameters
oSrc[in] Source MemoryBlock to be copied
Return values
0equal
<0lower
>0greater
tResult Copy ( cAsyncMemoryBlock oSrc)

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_OKno error
ERR_MEMORYmemory error
tResult Free ( )

Lock MemoryBlock and free memory is allocated and not assigned *.

Return values
STATUS_OKno Error
ERR_MEMORYno memory allocated or assigned
tInt GetSize ( )

Get size of MemoryBlock.

Returns
Size of MemoryBlock
This method is real-time safe.
See The ADTF Real-Time Extension.
tResult ReadLock ( void **  ppMem,
const tBool  bWait = tTrue 
)

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_OKno Error
ERR_POINTERppMem is NULL
ERR_UNEXPECTEDno memory is allocated
ERR_RESSOURCE_IN_USEif memory is locked and bWait is tFalse
tResult Unlock ( void  )

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_OKno Error
ERR_UNEXPECTEDno access active or no memory allocated
tResult WaitNewData ( tInt  nTimeout = -1)

Wait for the NewDataEvent which is set by unlocking a write access.

Parameters
nTimeout[in] Timeout, default = -1 (INFINITE)
Return values
STATUS_OKno error
ERR_TIMEOUTwait error / timeout
tResult WriteLock ( void **  ppMem,
const tBool  bWait = tTrue 
)

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_OKno Error
ERR_POINTERppMem is NULL
ERR_UNEXPECTEDno memory is allocated
ERR_RESSOURCE_IN_USEif memory is locked and bWait is tFalse

Copyright © Audi Electronics Venture GmbH. All rights reserved. (Generated on Fri Mar 22 2019 by doxygen 1.8.10)