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>
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) |
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; ... };
| MITHREAD::CONTAINERITEMSYNC::CONTAINERITEMSYNC | ( | ) |
Default ctor.
| MITHREAD::CONTAINERITEMSYNC::~CONTAINERITEMSYNC | ( | ) |
Default dtor.
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.
| 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'. |
1.6.1