Browse Source

* Add guardian pattern to syncobjs

Michaël Van Canneyt 1 week ago
parent
commit
3d74d0ceb1
1 changed files with 32 additions and 0 deletions
  1. 32 0
      packages/fcl-base/src/syncobjs.pp

+ 32 - 0
packages/fcl-base/src/syncobjs.pp

@@ -262,6 +262,22 @@ type
     property NextSpinCycleWillYield: Boolean read GetNextSpinCycleWillYield;
     property NextSpinCycleWillYield: Boolean read GetNextSpinCycleWillYield;
   end;
   end;
 
 
+  // Guardian pattern. Use to see if an object was freed or not by adding a guardian instance to it.
+  
+  IGuardian = interface
+    function GetIsDismantled: Boolean;
+    procedure Dismantle;
+    property IsDismantled: Boolean read GetIsDismantled;
+  end;
+
+  TGuardian = class(TInterfacedObject, IGuardian)
+  private
+    FIsDismantled: Boolean;
+    function GetIsDismantled: Boolean;
+  public
+    procedure Dismantle;
+    property IsDismantled: Boolean read GetIsDismantled;
+  end;
 
 
 implementation
 implementation
 
 
@@ -1206,4 +1222,20 @@ begin
   until (lElapsedTime >= lWaitTime) or lWait.NextSpinCycleWillYield;
   until (lElapsedTime >= lWaitTime) or lWait.NextSpinCycleWillYield;
 end;
 end;
 
 
+{ ---------------------------------------------------------------------
+  TGuardian
+  ---------------------------------------------------------------------}
+
+
+procedure TGuardian.Dismantle;
+begin
+  FIsDismantled := True;
+end;
+
+function TGuardian.GetIsDismantled: Boolean;
+begin
+  Result := FIsDismantled;
+end;
+
+
 end.
 end.