#include <MessageBuffers.h>
Inherits CLockMechanism.
Public Member Functions | |
CMessagePool () | |
Constructor. | |
virtual | ~CMessagePool () |
Destructor. | |
bool | Initialize (UINT32 numbuffers) |
Initialize 'numbuffers' empty CMessage objects. | |
bool | Deinitialize () |
Free memory, clean up anything. | |
Protected Member Functions | |
CMessage * | acquire_reference () |
Obtain a free (refcount 0) CMessage object. | |
bool | putback_reference (CMessage *ref) |
Put reference back (decrement reference count and clear CMessage if refcount is zero). | |
bool | increment_referencecount (CMessage *buffer_ref) |
Increment reference count by 1 for a already taken CMessage (by get_reference()). | |
Private Attributes | |
bool | m_bInitialized |
UINT32 | m_iSharedReferences |
will assert on UnInitialize() | |
UINT32 | m_iNumBuffers |
amount of CMessage buffers | |
CMessage * | m_pCMessages |
'numbuffers' messages | |
UINT32 * | m_pTakenBuffer |
reference counter buffer (0 - not used) | |
Friends | |
class | CNetworkQueue |
Using C++ STL this could be done much more easily, but implementation on Nios2 platform did not work (reason not fully known, stack issues suspected). This CMessageBuffer was created as an inferior, but working solution.
Implementation details:
Definition at line 23 of file MessageBuffers.h.
CMessagePool::CMessagePool | ( | ) |
CMessagePool::~CMessagePool | ( | ) | [virtual] |
Destructor.
Definition at line 32 of file MessageBuffers.cpp.
bool CMessagePool::Initialize | ( | UINT32 | numbuffers | ) |
Initialize 'numbuffers' empty CMessage objects.
This method initializes 'numbuffers' CMessage object storage locations to avoid huge static and stack data.
numbuffers | amount of CMessage buffers in pool |
true | successfully initializes to 'numbuffers' buffers in pool | |
false | something happened (mutex, already initialized) |
Definition at line 51 of file MessageBuffers.cpp.
Referenced by CNetworkQueue::create().
bool CMessagePool::Deinitialize | ( | ) |
Free memory, clean up anything.
This method deinitializes (frees, cleans up) CMessage object storage pool.
true | successfully deinitialized | |
false | something happened, unsuccessful deinitialization (mutex) user programmer: treat it as not deinitialized at all |
Definition at line 92 of file MessageBuffers.cpp.
Referenced by CNetworkQueue::close(), CNetworkQueue::create(), and ~CMessagePool().
CMessage * CMessagePool::acquire_reference | ( | ) | [protected] |
Obtain a free (refcount 0) CMessage object.
This method looks around a pool for a 'free' (not already taken) CMessage buffer and returns it in case it was found. The reference count for that pool element is increased to mark that one (1) requested it.
!=NULL | one pool member returned | |
NULL | something happened, no pool member returned obviously (not initialized, mutex or any buffer is taken) |
Definition at line 129 of file MessageBuffers.cpp.
Referenced by CNetworkQueue::obtainReference().
bool CMessagePool::putback_reference | ( | CMessage * | ref | ) | [protected] |
Put reference back (decrement reference count and clear CMessage if refcount is zero).
This method looks around a pool for the 'ref' (already taken) CMessage buffer and in case it was found, the reference count for that pool element is decreased by one (1). After that, it is checked whether the reference count has reached zero (no references) again. If that is the case, the CMessage buffer is cleared. For subsequent calls to acquire_reference, this buffer might be delivered again, because no code location is using it any more.
ref | buffer reference already taken |
true | successfully put back (does NOT mean that this was the last reference so the buffer is available again!) | |
false | reference count NOT decremented (no init, mutex, buffer_ref was not found or not taken at all) |
Definition at line 221 of file MessageBuffers.cpp.
Referenced by CNetworkQueue::putbackReference().
bool CMessagePool::increment_referencecount | ( | CMessage * | buffer_ref | ) | [protected] |
Increment reference count by 1 for a already taken CMessage (by get_reference()).
This method looks around a pool for the 'buffer_ref' (already taken) CMessage buffer and in case it was found, the reference count for that pool element is increased by one (1).
buffer_ref | buffer reference already taken |
true | reference count incremented by one | |
false | reference count NOT incremented (no init, mutex, buffer_ref was not found or not taken at all) |
Definition at line 170 of file MessageBuffers.cpp.
Referenced by CNetworkQueue::incrementReferenceCount().
friend class CNetworkQueue [friend] |
Definition at line 25 of file MessageBuffers.h.
bool CMessagePool::m_bInitialized [private] |
Definition at line 53 of file MessageBuffers.h.
Referenced by acquire_reference(), CMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().
UINT32 CMessagePool::m_iSharedReferences [private] |
will assert on UnInitialize()
Definition at line 56 of file MessageBuffers.h.
Referenced by acquire_reference(), CMessagePool(), Deinitialize(), Initialize(), and putback_reference().
UINT32 CMessagePool::m_iNumBuffers [private] |
amount of CMessage buffers
Definition at line 59 of file MessageBuffers.h.
Referenced by acquire_reference(), CMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().
CMessage* CMessagePool::m_pCMessages [private] |
'numbuffers' messages
Definition at line 62 of file MessageBuffers.h.
Referenced by acquire_reference(), CMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().
UINT32* CMessagePool::m_pTakenBuffer [private] |
reference counter buffer (0 - not used)
Definition at line 65 of file MessageBuffers.h.
Referenced by acquire_reference(), CMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().