MITHREAD::CONTAINERITEMSYNC Class Reference

This class is a solution to the issue of synchronizing container contents without using a synchronization object per container item. More...

#include <mi32/containeritemsync.h>

List of all members.

Classes

class  OBJECT
 This class holds the lock on the synchronization object until the dtor or the Release() method is called. More...

Public Member Functions

 CONTAINERITEMSYNC ()
 ~CONTAINERITEMSYNC ()
void AcquireSyncObject (PTRUINT ItemID, OBJECT &SyncObject)

Detailed Description

This class is a solution to the issue of synchronizing container contents without using a synchronization object per container item.

Example below:

   class CONTAINER {
      public:
         class ITEM {
            ...
            private:
               MITHREAD::CONTAINERITEMSYNC::OBJECT m_ItemLock;
               ...
            };
         ...

         ITEM& GetItem (
            INT32 ItemNum
            ) {
            ...
            // Wait until other thread has released its lock on 'ItemNum'
            m_ContainerSync.AcquireSyncObject(ItemNum, m_ItemArray[ItemNum].m_ItemLock);
            ...
            return (m_ItemArray[ItemNum]);      // Exclusive ownership granted to 'ItemNum' for the life of the calling code's ITEM instance. 
            }
      
      private:
         std::vector<ITEM> m_ItemArray;
         MITHREAD::CONTAINERITEMSYNC m_ContainerSync;
         ...
      };

Constructor & Destructor Documentation

MITHREAD::CONTAINERITEMSYNC::CONTAINERITEMSYNC (  ) 

Default ctor.

MITHREAD::CONTAINERITEMSYNC::~CONTAINERITEMSYNC (  ) 

Default dtor.


Member Function Documentation

void MITHREAD::CONTAINERITEMSYNC::AcquireSyncObject ( PTRUINT  ItemID,
OBJECT SyncObject 
)

Acquire a locked synchronization object for the 'ItemID' specified.

If an 'ItemID' is in the cache, this method will block until the other thread's lock on that 'ItemID' is released and the lock is granted for the calling thread. This method will call SyncObject.Release() before acquiring a new lock.

Parameters:
ItemID This value must be unique in regards to the container.
SyncObject Either the dtor or the Release() method will release this thread's lock on 'ItemID'.

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

Generated on Sun Oct 7 21:36:37 2012 for TNTsdk 2012 by  doxygen 1.6.1