Implementing first "strategy" for proof of concept

This commit is contained in:
Michael Schimmel
2025-07-11 11:06:18 +02:00
parent 644b6074d6
commit 487169afe0
20 changed files with 1761 additions and 274 deletions
+10 -7
View File
@@ -23,6 +23,9 @@ type
Receiver: T; // The registered interface instance (the event sink).
end;
// Notify function. If this results false, it will be removed from the notify list
TNotifyProc = reference to function(const Obj: T): Boolean;
strict private
// Head of the linked list. The pointer value itself is repurposed for a spinlock.
// Bit 0 of the address stores the lock state (0 = locked, 1 = unlocked).
@@ -36,9 +39,9 @@ type
public
// Initializes the list in an unlocked state.
procedure Create;
class operator Initialize(out Dest: TMycNotifyList<T>);
// Safely clears all registered receivers and cleans up resources.
procedure Destroy;
procedure Finalize;
// Registers a receiver interface and returns an opaque tag for later unsubscription.
function Advise(const Receiver: T): TTag;
// Unregisters a single receiver using its subscription tag.
@@ -54,17 +57,17 @@ type
// Invokes a predicate for each registered receiver.
// If the predicate returns false, the receiver is detached from further notifications
// by setting its interface reference to nil. The list item itself is not freed here.
procedure Notify(Func: TPredicate<T>);
procedure Notify(const Func: TNotifyProc);
end;
implementation
procedure TMycNotifyList<T>.Create;
class operator TMycNotifyList<T>.Initialize(out Dest: TMycNotifyList<T>);
begin
NativeUInt(FList) := 1;
NativeUInt(Dest.FList) := 1;
end;
procedure TMycNotifyList<T>.Destroy;
procedure TMycNotifyList<T>.Finalize;
begin
Lock;
UnadviseAll;
@@ -114,7 +117,7 @@ begin
Result := NativeUInt(FList) and 1 = 0;
end;
procedure TMycNotifyList<T>.Notify(Func: TPredicate<T>);
procedure TMycNotifyList<T>.Notify(const Func: TNotifyProc);
var
Item: PItem;
Last: PItem;