#include <NQMessagePool.h>
Inherits CNQLockMechanism.
Public Member Functions | |
CNQMessagePool () | |
Constructor. | |
virtual | ~CNQMessagePool () |
Destructor. | |
bool | Initialize (UINT32 numbuffers) |
Initialize 'numbuffers' empty CNQMessage objects. | |
bool | Deinitialize () |
Free memory, clean up anything. | |
Protected Member Functions | |
CNQMessage * | acquire_reference () |
Obtain a free (refcount 0) CNQMessage object. | |
bool | putback_reference (CNQMessage *ref) |
Put reference back (decrement reference count and clear CNQMessage if refcount is zero). | |
bool | increment_referencecount (CNQMessage *buffer_ref) |
Increment reference count by 1 for a already taken CNQMessage (by get_reference()). | |
Private Attributes | |
bool | m_bInitialized |
UINT32 | m_iSharedReferences |
will assert on UnInitialize() | |
UINT32 | m_iNumBuffers |
amount of CNQMessage buffers | |
CNQMessage * | 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 CNQMessagePool was created as an inferior, but working solution.
Implementation details:
Definition at line 23 of file NQMessagePool.h.
CNQMessagePool::CNQMessagePool | ( | ) |
CNQMessagePool::~CNQMessagePool | ( | ) | [virtual] |
Destructor.
Definition at line 33 of file NQMessagePool.cpp.
bool CNQMessagePool::Initialize | ( | UINT32 | numbuffers | ) |
Initialize 'numbuffers' empty CNQMessage objects.
This method initializes 'numbuffers' CNQMessage object storage locations to avoid huge static and stack data.
numbuffers | amount of CNQMessage buffers in pool |
true | successfully initializes to 'numbuffers' buffers in pool | |
false | something happened (mutex, already initialized) |
Definition at line 52 of file NQMessagePool.cpp.
Referenced by CNetworkQueue::create().
bool CNQMessagePool::Deinitialize | ( | ) |
Free memory, clean up anything.
This method deinitializes (frees, cleans up) CNQMessage object storage pool.
true | successfully deinitialized | |
false | something happened, unsuccessful deinitialization (mutex) user programmer: treat it as not deinitialized at all |
Definition at line 93 of file NQMessagePool.cpp.
Referenced by CNetworkQueue::close(), CNetworkQueue::create(), and ~CNQMessagePool().
CNQMessage * CNQMessagePool::acquire_reference | ( | ) | [protected] |
Obtain a free (refcount 0) CNQMessage object.
This method looks around a pool for a 'free' (not already taken) CNQMessage 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 130 of file NQMessagePool.cpp.
Referenced by CNetworkQueue::obtainReference().
bool CNQMessagePool::putback_reference | ( | CNQMessage * | ref | ) | [protected] |
Put reference back (decrement reference count and clear CNQMessage if refcount is zero).
This method looks around a pool for the 'ref' (already taken) CNQMessage 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 CNQMessage 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 222 of file NQMessagePool.cpp.
Referenced by CNetworkQueue::putbackReference().
bool CNQMessagePool::increment_referencecount | ( | CNQMessage * | buffer_ref | ) | [protected] |
Increment reference count by 1 for a already taken CNQMessage (by get_reference()).
This method looks around a pool for the 'buffer_ref' (already taken) CNQMessage 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 171 of file NQMessagePool.cpp.
Referenced by CNetworkQueue::incrementReferenceCount().
friend class CNetworkQueue [friend] |
Definition at line 25 of file NQMessagePool.h.
bool CNQMessagePool::m_bInitialized [private] |
Definition at line 53 of file NQMessagePool.h.
Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().
UINT32 CNQMessagePool::m_iSharedReferences [private] |
will assert on UnInitialize()
Definition at line 56 of file NQMessagePool.h.
Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), Initialize(), and putback_reference().
UINT32 CNQMessagePool::m_iNumBuffers [private] |
amount of CNQMessage buffers
Definition at line 59 of file NQMessagePool.h.
Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().
CNQMessage* CNQMessagePool::m_pCMessages [private] |
'numbuffers' messages
Definition at line 62 of file NQMessagePool.h.
Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().
UINT32* CNQMessagePool::m_pTakenBuffer [private] |
reference counter buffer (0 - not used)
Definition at line 65 of file NQMessagePool.h.
Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().