void CSubject::PostChanges( System::Changes::BitMask changedBits ) { if ( !m_observerList.empty() ) { typedef std::pair<IObserver*, u32> PostData; PostData* aPostData = NULL; u32 nNotificationsToPost = 0; // Double check to avoid unnecessary lock acquisition { SpinWait::Lock lock(m_observerListMutex); aPostData = (PostData*)alloca( m_observerList.size() * sizeof(PostData) ); ObserverList::iterator it = m_observerList.begin(); for ( ; it != m_observerList.end(); ++it ) { u32 changedBitsOfInterest = GetBitsToPost( *it, changedBits ); if ( changedBitsOfInterest ) { aPostData[nNotificationsToPost] = std::make_pair(it->m_pObserver, changedBitsOfInterest); ++nNotificationsToPost; } } } // Posting is done outside of the lock for ( u32 i = 0; i < nNotificationsToPost; ++i ) { aPostData[i].first->ChangeOccurred( this, aPostData[i].second ); } } } // CSubject::PostChanges
virtual void PostChanges( System::Changes::BitMask changedBits ) { if ( !m_observerList.empty() ) { typedef std::pair<IObserver*, u32> PostData; PostData* aPostData = NULL; u32 nNotificationsToPost = 0; // Double check to avoid unnecessary lock acquisition { std::lock_guard<std::mutex> lock(m_observerListMutex); aPostData = (PostData*)alloca( m_observerList.size() * sizeof(PostData) ); for ( auto& it : m_observerList) { std::uint32_t changedBitsOfInterest = GetBitsToPost( it, changedBits ); if ( changedBitsOfInterest ) { aPostData[nNotificationsToPost] = std::make_pair(it->m_pObserver, changedBitsOfInterest); ++nNotificationsToPost; } } } // Posting is done outside of the lock for ( u32 i = 0; i < nNotificationsToPost; ++i ) { aPostData[i].first->ChangeOccurred( this, aPostData[i].second ); } } } // CSubject::PostChanges
/////////////////////////////////////////////////////////////////////////////// // PostChanges - Post a change to all observers of this subject void CSubject::PostChanges( System::Changes::BitMask changedBits ) { #if SUPPORT_CONCURRENT_ATTACH_DETACH_TO_SUBJECTS SpinWait::Lock lock(m_observerListMutex); #endif ObserverList::iterator it = m_observerList.begin(); for ( ; it != m_observerList.end(); ++it ) { u32 changedBitsOfInterest = GetBitsToPost( *it, changedBits ); if ( changedBitsOfInterest ) { it->m_pObserver->ChangeOccurred( this, changedBitsOfInterest ); } } }
// PostChanges - Post a change to all observers of this subject virtual void PostChanges( System::Changes::BitMask changedBits ) { #if SUPPORT_CONCURRENT_ATTACH_DETACH_TO_SUBJECTS std::lock_guard<std::mutex> lock(m_observerListMutex); #endif ObserverList::iterator it = m_observerList.begin(); for ( ; it != m_observerList.end(); ++it ) { std::uint32_t changedBitsOfInterest = GetBitsToPost( *it, changedBits ); if ( changedBitsOfInterest ) { it->m_pObserver->ChangeOccurred( this, changedBitsOfInterest ); } } }