CMessagePool Class Reference

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

#include <MessageBuffers.h>

Inherits CLockMechanism.

Collaboration diagram for CMessagePool:

Collaboration graph
[legend]

List of all members.

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

CMessageacquire_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
CMessagem_pCMessages
 'numbuffers' messages
UINT32 * m_pTakenBuffer
 reference counter buffer (0 - not used)

Friends

class CNetworkQueue


Detailed Description

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

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:

Date:
SW (Nov 2006 to Mar 2007)

Definition at line 23 of file MessageBuffers.h.


Constructor & Destructor Documentation

CMessagePool::CMessagePool (  ) 

Constructor.

Definition at line 19 of file MessageBuffers.cpp.

CMessagePool::~CMessagePool (  )  [virtual]

Destructor.

Definition at line 32 of file MessageBuffers.cpp.

Here is the call graph for this function:


Member Function Documentation

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.

Parameters:
numbuffers amount of CMessage 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 51 of file MessageBuffers.cpp.

Referenced by CNetworkQueue::create().

Here is the call graph for this function:

Here is the caller graph for this function:

bool CMessagePool::Deinitialize (  ) 

Free memory, clean up anything.

This method deinitializes (frees, cleans up) CMessage 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 92 of file MessageBuffers.cpp.

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

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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 129 of file MessageBuffers.cpp.

Referenced by CNetworkQueue::obtainReference().

Here is the call graph for this function:

Here is the caller graph for this function:

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.

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 221 of file MessageBuffers.cpp.

Referenced by CNetworkQueue::putbackReference().

Here is the call graph for this function:

Here is the caller graph for this function:

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

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 170 of file MessageBuffers.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 MessageBuffers.h.


Member Data Documentation

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]

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


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

Generated on Wed Apr 16 18:22:16 2008 for NetworkQueue by  doxygen 1.5.5