Pārlūkot izejas kodu

Merge pull request #122 from jkour/Pool-AV

[pool] An AV occurs in TPoolItem
Exilon 9 mēneši atpakaļ
vecāks
revīzija
3fb5b8448f
2 mainītis faili ar 48 papildinājumiem un 27 dzēšanām
  1. 4 4
      Quick.Pooling.pas
  2. 44 23
      samples/delphi/QuickPooling/HttpPool.dproj

+ 4 - 4
Quick.Pooling.pas

@@ -295,22 +295,22 @@ end;
 
 
 function TPoolItem<T>._Release: Integer;
 function TPoolItem<T>._Release: Integer;
 begin
 begin
-  fLock.Enter;
   {$IFDEF DEBUG_OBJPOOL}
   {$IFDEF DEBUG_OBJPOOL}
   TDebugger.Trace(Self,'Released Pool item');
   TDebugger.Trace(Self,'Released Pool item');
   {$ENDIF}
   {$ENDIF}
   try
   try
-    Dec(fRefCount);
-    Result := fRefCount;
+    result:=AtomicDecrement(fRefCount);
     if Result = 0 then
     if Result = 0 then
     begin
     begin
       FreeAndNil(fItem);
       FreeAndNil(fItem);
+      // The following is take from TInterfacedObject._Release()
+      // Mark the refcount field so that any refcounting during destruction doesn't infinitely recurse.
+      __MarkDestroying(Self);
       Destroy;
       Destroy;
     end
     end
     else fLastAccess := Now;
     else fLastAccess := Now;
   finally
   finally
     if fRefCount = 1 then fSemaphore.Release;
     if fRefCount = 1 then fSemaphore.Release;
-    fLock.Leave;
   end;
   end;
 end;
 end;
 
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 44 - 23
samples/delphi/QuickPooling/HttpPool.dproj


Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels