ADTF
asyncmemoryblock.h
Go to the documentation of this file.
1 
7 #ifndef __ASYNC_MEMORY_BLOCK_HEADER
8 #define __ASYNC_MEMORY_BLOCK_HEADER
9 
10 #include <mutex>
11 #include <condition_variable>
12 
13 namespace A_UTILS_NS
14 {
15 
22 {
24 
25  public:
30 
34  virtual ~cAsyncMemoryBlock();
35 
47  tResult Alloc(tInt nSize);
48 
62  tResult Assign(void* pMem, tInt nSize);
63 
73 
91  tResult ReadLock(void** ppMem, const tBool bWait=tTrue);
92 
111  tResult WriteLock(void** ppMem, const tBool bWait=tTrue);
112 
124 
136 
149 
159 
170  tResult WaitNewData(tInt nTimeout=-1);
171 
172  private:
173  void* m_pMem;
176 
180 
181  std::recursive_mutex m_oMutexChangeState;
182 
183  std::mutex m_mutexLock;
184  std::mutex m_mutexNoReader;
185  std::mutex m_mutexNewData;
186  std::condition_variable m_CondEventNoReader;
187  std::condition_variable m_CondNewData;
188  std::condition_variable m_CondMutexLock;
189 };
190 
191 } // namespace A_UTILS_NS
192 
193 #endif // __ASYNC_MEMORY_BLOCK_HEADER
int tInt
type definition for signed integer value (platform and compiler dependent type).
bool tBool
The tBool defines the type for the Values tTrue and tFalse (platform and compiler dependent).
Thread safe smart pointer for raw memory blocks.
std::condition_variable m_CondNewData
condition_variable to signal a waiting writer that all readers finished
std::mutex m_mutexLock
mutex for short locks (like counter increments)
std::condition_variable m_CondEventNoReader
Mutex for locking the conditional variable depending on 'newData'.
std::recursive_mutex m_oMutexChangeState
number of writers which are waiting
tInt GetSize()
Get size of MemoryBlock.
tInt m_nSize
memory assigned not alloced (not to be freed afterwards)
std::condition_variable m_CondMutexLock
event to signal new data
tInt m_nWriterWaitCount
write access currently active
tResult Alloc(tInt nSize)
Allocates new memory for the MemoryBlock *.
tResult Assign(void *pMem, tInt nSize)
Assigns memory to the MemoryBlock object which has already been allocated.
std::mutex m_mutexNoReader
mutex for locking MemoryBlock for other access
tResult Free()
Lock MemoryBlock and free memory is allocated and not assigned *.
tBool m_bWriteAccess
count of active readers
tInt Compare(cAsyncMemoryBlock &oSrc)
Compares size and content with another MemoryBlock.
tResult WriteLock(void **ppMem, const tBool bWait=tTrue)
Try to lock memory for write access.
tBool m_bMemAssigned
memory pointer
virtual ~cAsyncMemoryBlock()
Destructor.
tResult ReadLock(void **ppMem, const tBool bWait=tTrue)
Try to lock memory for read access.
tResult WaitNewData(tInt nTimeout=-1)
Wait for the NewDataEvent which is set by unlocking a write access.
tResult Copy(cAsyncMemoryBlock &oSrc)
Copies the content of the source MemoryBlock.
std::mutex m_mutexNewData
Mutex for locking the condVariable depending on 'noReader'.
cAsyncMemoryBlock()
Default constructor.
tResult Unlock(void)
Unlock MemoryBlock.
#define tTrue
Value for tBool.
Definition: constants.h:62
#define A_UTILS_D(__pclassname_)
Helper macro for d-pattern definitions.
Definition: d_ptr.h:270
ADTF A_UTIL Namespace - Within adtf this is used as adtf::util or adtf_util.
Definition: d_ptr.h:11