Parcourir la source

Merge pull request #122 from jkour/Pool-AV

[pool] An AV occurs in TPoolItem
Exilon il y a 11 mois
Parent
commit
3fb5b8448f
2 fichiers modifiés avec 48 ajouts et 27 suppressions
  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;
 begin
-  fLock.Enter;
   {$IFDEF DEBUG_OBJPOOL}
   TDebugger.Trace(Self,'Released Pool item');
   {$ENDIF}
   try
-    Dec(fRefCount);
-    Result := fRefCount;
+    result:=AtomicDecrement(fRefCount);
     if Result = 0 then
     begin
       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;
     end
     else fLastAccess := Now;
   finally
     if fRefCount = 1 then fSemaphore.Release;
-    fLock.Leave;
   end;
 end;
 

Fichier diff supprimé car celui-ci est trop grand
+ 44 - 23
samples/delphi/QuickPooling/HttpPool.dproj


Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff