Index: src/libchcore/TSubTaskArray.cpp =================================================================== diff -u -r9ba9390b8f79c7a3fd1f9d6d9e92038d92222621 -rc6d96d4152aab0785a5f850b5ed9eb4a3584fd91 --- src/libchcore/TSubTaskArray.cpp (.../TSubTaskArray.cpp) (revision 9ba9390b8f79c7a3fd1f9d6d9e92038d92222621) +++ src/libchcore/TSubTaskArray.cpp (.../TSubTaskArray.cpp) (revision c6d96d4152aab0785a5f850b5ed9eb4a3584fd91) @@ -38,82 +38,20 @@ BEGIN_CHCORE_NAMESPACE -namespace details -{ - /////////////////////////////////////////////////////////////////////////// - // TTaskBasicProgressInfo - - TTaskBasicProgressInfo::TTaskBasicProgressInfo() : - m_stSubOperationIndex(0) - { - } - - TTaskBasicProgressInfo::~TTaskBasicProgressInfo() - { - } - - void TTaskBasicProgressInfo::ResetProgress() - { - boost::unique_lock lock(m_lock); - m_stSubOperationIndex = 0; - } - - void TTaskBasicProgressInfo::SetSubOperationIndex(size_t stSubOperationIndex) - { - boost::unique_lock lock(m_lock); - m_stSubOperationIndex = stSubOperationIndex; - } - - size_t TTaskBasicProgressInfo::GetSubOperationIndex() const - { - boost::shared_lock lock(m_lock); - return m_stSubOperationIndex; - } - - void TTaskBasicProgressInfo::IncreaseSubOperationIndex() - { - boost::unique_lock lock(m_lock); - ++m_stSubOperationIndex; - } - - void TTaskBasicProgressInfo::Serialize(TReadBinarySerializer& rSerializer) - { - using Serializers::Serialize; - - size_t stSubOperationIndex = 0; - Serialize(rSerializer, stSubOperationIndex); - - boost::unique_lock lock(m_lock); - - m_stSubOperationIndex = stSubOperationIndex; - } - - void TTaskBasicProgressInfo::Serialize(TWriteBinarySerializer& rSerializer) const - { - using Serializers::Serialize; - - size_t stSubOperationIndex = 0; - { - boost::shared_lock lock(m_lock); - stSubOperationIndex = m_stSubOperationIndex; - } - - Serialize(rSerializer, stSubOperationIndex); - } -} - /////////////////////////////////////////////////////////////////////////// // TSubTasksArray TSubTasksArray::TSubTasksArray() : m_pSubTaskContext(NULL), - m_eOperationType(eOperation_None) + m_eOperationType(eOperation_None), + m_lSubOperationIndex(0) { } TSubTasksArray::TSubTasksArray(const TOperationPlan& rOperationPlan, TSubTaskContext& rSubTaskContext) : m_pSubTaskContext(NULL), - m_eOperationType(eOperation_None) + m_eOperationType(eOperation_None), + m_lSubOperationIndex(0) { Init(rOperationPlan, rSubTaskContext); } @@ -125,7 +63,7 @@ void TSubTasksArray::Init(const TOperationPlan& rOperationPlan, TSubTaskContext& rSubTaskContext) { m_vSubTasks.clear(); - m_tProgressInfo.ResetProgress(); + m_lSubOperationIndex = 0; m_pSubTaskContext = &rSubTaskContext; m_eOperationType = rOperationPlan.GetOperationType(); @@ -161,7 +99,7 @@ void TSubTasksArray::ResetProgressAndStats() { - m_tProgressInfo.ResetProgress(); + InterlockedExchange(&m_lSubOperationIndex, 0); std::pair tupleRow; BOOST_FOREACH(tupleRow, m_vSubTasks) @@ -173,43 +111,21 @@ } } -void TSubTasksArray::SerializeProgress(TReadBinarySerializer& rSerializer) -{ - m_tProgressInfo.Serialize(rSerializer); - std::pair tupleRow; - BOOST_FOREACH(tupleRow, m_vSubTasks) - { - tupleRow.first->GetProgressInfo().Serialize(rSerializer); - } -} - -void TSubTasksArray::SerializeProgress(TWriteBinarySerializer& rSerializer) const -{ - m_tProgressInfo.Serialize(rSerializer); - std::pair tupleRow; - BOOST_FOREACH(tupleRow, m_vSubTasks) - { - tupleRow.first->GetProgressInfo().Serialize(rSerializer); - } -} - TSubTaskBase::ESubOperationResult TSubTasksArray::Execute(bool bRunOnlyEstimationSubTasks) { if(!m_pSubTaskContext) THROW_CORE_EXCEPTION(eErr_InternalProblem); TSubTaskBase::ESubOperationResult eResult = TSubTaskBase::eSubResult_Continue; - size_t stSubOperationIndex = m_tProgressInfo.GetSubOperationIndex(); + size_t stSize = m_vSubTasks.size(); + long lIndex = InterlockedCompareExchange(&m_lSubOperationIndex, 0, 0); - for(; stSubOperationIndex < m_vSubTasks.size() && eResult == TSubTaskBase::eSubResult_Continue; ++stSubOperationIndex) + while(lIndex < stSize && eResult == TSubTaskBase::eSubResult_Continue) { - std::pair& rCurrentSubTask = m_vSubTasks[stSubOperationIndex]; + std::pair& rCurrentSubTask = m_vSubTasks.at(lIndex); TSubTaskBasePtr spCurrentSubTask = rCurrentSubTask.first; - // set current sub-operation index to allow resuming - m_tProgressInfo.SetSubOperationIndex(stSubOperationIndex); - // if we run in estimation mode only, then stop processing and return to the caller if(bRunOnlyEstimationSubTasks && !rCurrentSubTask.second) { @@ -218,6 +134,8 @@ } eResult = spCurrentSubTask->Exec(); + + lIndex = InterlockedIncrement(&m_lSubOperationIndex); } return eResult; @@ -233,11 +151,12 @@ rSnapshot.Clear(); // current task - size_t stSubOperationIndex = m_tProgressInfo.GetSubOperationIndex(); - rSnapshot.SetCurrentSubtaskIndex(stSubOperationIndex); + // ugly const_cast - const method, non-const interlocked intrinsic and we're really not modifying the member... + long lIndex = InterlockedCompareExchange(const_cast(&m_lSubOperationIndex), 0L, 0L); + rSnapshot.SetCurrentSubtaskIndex(lIndex); // progress - for(stSubOperationIndex = 0; stSubOperationIndex < m_vSubTasks.size(); ++stSubOperationIndex) + for(size_t stSubOperationIndex = 0; stSubOperationIndex < m_vSubTasks.size(); ++stSubOperationIndex) { const std::pair& rCurrentSubTask = m_vSubTasks[stSubOperationIndex]; TSubTaskBasePtr spCurrentSubTask = rCurrentSubTask.first; Index: src/libchcore/TSubTaskArray.h =================================================================== diff -u -r9ba9390b8f79c7a3fd1f9d6d9e92038d92222621 -rc6d96d4152aab0785a5f850b5ed9eb4a3584fd91 --- src/libchcore/TSubTaskArray.h (.../TSubTaskArray.h) (revision 9ba9390b8f79c7a3fd1f9d6d9e92038d92222621) +++ src/libchcore/TSubTaskArray.h (.../TSubTaskArray.h) (revision c6d96d4152aab0785a5f850b5ed9eb4a3584fd91) @@ -34,42 +34,6 @@ class TOperationPlan; class TSubTaskContext; -class TReadBinarySerializer; -class TWriteBinarySerializer; - -namespace details -{ - /////////////////////////////////////////////////////////////////////////// - // TTaskBasicProgressInfo - - class LIBCHCORE_API TTaskBasicProgressInfo - { - public: - TTaskBasicProgressInfo(); - ~TTaskBasicProgressInfo(); - - void ResetProgress(); - - void SetSubOperationIndex(size_t stSubOperationIndex); - size_t GetSubOperationIndex() const; - void IncreaseSubOperationIndex(); - - void Serialize(TReadBinarySerializer& rSerializer); - void Serialize(TWriteBinarySerializer& rSerializer) const; - - private: - TTaskBasicProgressInfo(const TTaskBasicProgressInfo& rSrc); - - private: - volatile size_t m_stSubOperationIndex; // index of sub-operation from TOperationDescription - -#pragma warning(push) -#pragma warning(disable: 4251) - mutable boost::shared_mutex m_lock; -#pragma warning(pop) - }; -} - /////////////////////////////////////////////////////////////////////////// // TTaskBasicProgressInfo class LIBCHCORE_API TSubTasksArray @@ -105,10 +69,10 @@ #pragma warning(push) #pragma warning(disable: 4251) std::vector > m_vSubTasks; // pointer to the subtask object / part of the whole process / is this the part of estimation? - - details::TTaskBasicProgressInfo m_tProgressInfo; #pragma warning(pop) + volatile long m_lSubOperationIndex; // index of sub-operation from TOperationDescription + friend class TTaskProcessingGuard; }; Index: src/libchcore/TSubTaskContext.h =================================================================== diff -u -rb193a95402f2bf4c456fb9d65d111caaf6994823 -rc6d96d4152aab0785a5f850b5ed9eb4a3584fd91 --- src/libchcore/TSubTaskContext.h (.../TSubTaskContext.h) (revision b193a95402f2bf4c456fb9d65d111caaf6994823) +++ src/libchcore/TSubTaskContext.h (.../TSubTaskContext.h) (revision c6d96d4152aab0785a5f850b5ed9eb4a3584fd91) @@ -39,8 +39,6 @@ class TWorkerThreadController; class TTaskConfigTracker; class TLocalFilesystem; -class TTaskLocalStatsInfo; -class TTaskBasicProgressInfo; class TFileInfoArray; class TConfig; class TFileFiltersArray;