CNQMessagePool Class Reference

Implementation of platform (and stack) independent message buffers of type CNQMessage. More...

#include <NQMessagePool.h>

Inherits CNQLockMechanism.

Collaboration diagram for CNQMessagePool:

Collaboration graph
[legend]

List of all members.

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

CNQMessageacquire_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
CNQMessagem_pCMessages
 'numbuffers' messages
UINT32m_pTakenBuffer
 reference counter buffer (0 - not used)

Friends

class CNetworkQueue


Detailed Description

Implementation of platform (and stack) independent message buffers of type CNQMessage.

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:

Date:
SW (Nov 2006 to Mar 2007)

Definition at line 23 of file NQMessagePool.h.


Constructor & Destructor Documentation

CNQMessagePool::CNQMessagePool (  ) 

Constructor.

Definition at line 20 of file NQMessagePool.cpp.

CNQMessagePool::~CNQMessagePool (  )  [virtual]

Destructor.

Definition at line 33 of file NQMessagePool.cpp.

Here is the call graph for this function:


Member Function Documentation

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.

Parameters:
numbuffers amount of CNQMessage buffers in pool
Return values:
true successfully initializes to 'numbuffers' buffers in pool
false something happened (mutex, already initialized)
Note:
This function contains assert() which give more failure reasons during development/debugging.

Definition at line 52 of file NQMessagePool.cpp.

Referenced by CNetworkQueue::create().

Here is the call graph for this function:

Here is the caller graph for this function:

bool CNQMessagePool::Deinitialize (  ) 

Free memory, clean up anything.

This method deinitializes (frees, cleans up) CNQMessage object storage pool.

Return values:
true successfully deinitialized
false something happened, unsuccessful deinitialization (mutex) user programmer: treat it as not deinitialized at all
Note:
This function contains assert() which give more failure reasons during development/debugging.

Definition at line 93 of file NQMessagePool.cpp.

Referenced by CNetworkQueue::close(), CNetworkQueue::create(), and ~CNQMessagePool().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Return values:
!=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().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Parameters:
ref buffer reference already taken
Return values:
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)
Note:
This function contains assert() which gives more failure reasons during development/debugging.

Definition at line 222 of file NQMessagePool.cpp.

Referenced by CNetworkQueue::putbackReference().

Here is the call graph for this function:

Here is the caller graph for this function:

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).

Parameters:
buffer_ref buffer reference already taken
Return values:
true reference count incremented by one
false reference count NOT incremented (no init, mutex, buffer_ref was not found or not taken at all)
Note:
This function contains assert() which give more failure reasons during development/debugging.

Definition at line 171 of file NQMessagePool.cpp.

Referenced by CNetworkQueue::incrementReferenceCount().

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class CNetworkQueue [friend]

Definition at line 25 of file NQMessagePool.h.


Member Data Documentation

will assert on UnInitialize()

Definition at line 56 of file NQMessagePool.h.

Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), Initialize(), and putback_reference().

'numbuffers' messages

Definition at line 62 of file NQMessagePool.h.

Referenced by acquire_reference(), CNQMessagePool(), Deinitialize(), increment_referencecount(), Initialize(), and putback_reference().

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().


The documentation for this class was generated from the following files:

Generated on Tue Apr 22 18:19:59 2008 for NetworkQueue by  doxygen 1.5.5