TaskFactory added

This commit is contained in:
Michael Schimmel
2025-05-26 00:27:09 +02:00
parent 10ef4cbcf2
commit 95fddb0181
13 changed files with 1292 additions and 251 deletions
+22 -15
View File
@@ -56,6 +56,8 @@ type
// Pushes an item onto the stack.
procedure Push(const Data: T); inline;
procedure Clear;
// Allocates an aligned memory block for a stack item.
function Alloc: PItem; inline;
// Pushes a pre-allocated item pointer onto the SList.
@@ -183,22 +185,8 @@ begin
end;
class operator TMycAtomicStack<T>.Finalize(var Dest: TMycAtomicStack<T>);
var
item: PItem;
begin
// Use Dest to access fields and call instance methods
// on the record instance being finalized
item := Dest.PopPtr; // Call instance method PopPtr via Dest
while item <> nil do
begin
item.Data := Default(T);
FreeMemAligned(item); // Global procedure
item := Dest.PopPtr; // Call instance method PopPtr via Dest
end;
if Dest.FSList <> nil then // Check if FSList was initialized
begin
Dest.FSList.Free; // Call instance method Free on FSList via Dest
end;
Dest.Clear;
end;
function TMycAtomicStack<T>.Alloc: PItem;
@@ -209,6 +197,25 @@ begin
Result.Data := Default(T);
end;
procedure TMycAtomicStack<T>.Clear;
var
item: PItem;
begin
// Use Dest to access fields and call instance methods
// on the record instance being finalized
item := PopPtr; // Call instance method PopPtr via Dest
while item <> nil do
begin
item.Data := Default(T);
FreeMemAligned(item); // Global procedure
item := PopPtr; // Call instance method PopPtr via Dest
end;
if FSList <> nil then // Check if FSList was initialized
begin
FSList.Free; // Call instance method Free on FSList via Dest
end;
end;
function TMycAtomicStack<T>.Pop: T;
begin
// Instance method