Browse Source

Fixing too strong assertion

Source commit: d55dd03aa4a5dcbfe26fa97d638ee715d0e29e24
Martin Prikryl 8 years ago
parent
commit
eef589624f
3 changed files with 25 additions and 14 deletions
  1. 17 12
      source/core/Queue.cpp
  2. 7 2
      source/core/Terminal.cpp
  3. 1 0
      source/core/Terminal.h

+ 17 - 12
source/core/Queue.cpp

@@ -2113,20 +2113,25 @@ void __fastcall TTransferQueueItem::ProgressUpdated()
     {
       TGuard Guard(FSection);
       DebugAssert(FParallelOperation != NULL);
-      DebugAssert((FProgressData->Operation == foCopy) || (FProgressData->Operation == foCalculateSize));
-      if (FProgressData->Operation == foCopy)
+      // Won't be initialized, if the operation is not eligible for parallel transfers (like cpDelete).
+      // We can probably move the check outside of the guard.
+      if (FParallelOperation->IsInitialized())
       {
-        Add = FParallelOperation->ShouldAddClient();
-        if (Add)
+        DebugAssert((FProgressData->Operation == foCopy) || (FProgressData->Operation == foCalculateSize));
+        if (FProgressData->Operation == foCopy)
         {
-          DWORD Now = GetTickCount();
-          Force =
-            (Now - FLastParallelOperationAdded >= 5*1000) &&
-            (TimeToSeconds(FProgressData->TotalTimeLeft()) >= FQueue->ParallelDurationThreshold);
-          LastParallelOperationAddedPrev = FLastParallelOperationAdded;
-          // update now already to prevent race condition, but we will have to rollback it back,
-          // if we actually do not add the parallel operation
-          FLastParallelOperationAdded = Now;
+          Add = FParallelOperation->ShouldAddClient();
+          if (Add)
+          {
+            DWORD Now = GetTickCount();
+            Force =
+              (Now - FLastParallelOperationAdded >= 5*1000) &&
+              (TimeToSeconds(FProgressData->TotalTimeLeft()) >= FQueue->ParallelDurationThreshold);
+            LastParallelOperationAddedPrev = FLastParallelOperationAdded;
+            // update now already to prevent race condition, but we will have to rollback it back,
+            // if we actually do not add the parallel operation
+            FLastParallelOperationAdded = Now;
+          }
         }
       }
     }

+ 7 - 2
source/core/Terminal.cpp

@@ -781,11 +781,16 @@ TParallelOperation::~TParallelOperation()
   WaitFor();
 }
 //---------------------------------------------------------------------------
+bool TParallelOperation::IsInitialized()
+{
+  return (FMainOperationProgress != NULL);
+}
+//---------------------------------------------------------------------------
 bool TParallelOperation::ShouldAddClient()
 {
   bool Result;
-  // initialized already?
-  if (FSection.get() == NULL)
+  // TTransferQueueItem::ProgressUpdated() already checks IsInitialized() before calling this
+  if (!IsInitialized())
   {
     Result = false;
   }

+ 1 - 0
source/core/Terminal.h

@@ -808,6 +808,7 @@ public:
     TStrings * AFiles, const UnicodeString & TargetDir, const TCopyParamType * CopyParam, int Params,
     TFileOperationProgressType * MainOperationProgress, const UnicodeString & MainName);
 
+  bool IsInitialized();
   void WaitFor();
   bool ShouldAddClient();
   void AddClient();