Bugfix in TEvent, DataServer Push-Mode

This commit is contained in:
Michael Schimmel
2025-06-24 18:32:32 +02:00
parent 35413f5966
commit 3797507d95
13 changed files with 251 additions and 69 deletions
+51
View File
@@ -3,6 +3,7 @@ unit Myc.Core.Lazy;
interface
uses
System.Classes,
System.SysUtils,
Myc.Signals,
Myc.Lazy;
@@ -76,6 +77,19 @@ type
constructor Create(const AChanged: TSignal.ISignal; const AProc: TFunc<T>);
end;
TMycProtectedWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TMutable<T>.IWriteable)
private
FValue: T;
FChanged: TEvent;
FLock: Integer;
protected
function GetChanged: TSignal;
function GetValue: T;
public
constructor Create(const AValue: T);
procedure SetValue(const Value: T);
end;
implementation
{ TMycNullMutable<T> }
@@ -204,4 +218,41 @@ begin
Result := FProc();
end;
{ TMycProtectedWriteableMutable<T> }
constructor TMycProtectedWriteableMutable<T>.Create(const AValue: T);
begin
inherited Create;
FValue := AValue;
FChanged := TEvent.CreateEvent;
end;
function TMycProtectedWriteableMutable<T>.GetChanged: TSignal;
begin
Result := FChanged.Signal;
end;
function TMycProtectedWriteableMutable<T>.GetValue: T;
begin
while AtomicExchange(FLock, 1) = 1 do
YieldProcessor;
try
Result := FValue;
finally
AtomicExchange(FLock, 0);
end;
end;
procedure TMycProtectedWriteableMutable<T>.SetValue(const Value: T);
begin
while AtomicExchange(FLock, 1) = 1 do
YieldProcessor;
try
FValue := Value;
FChanged.Notify;
finally
AtomicExchange(FLock, 0);
end;
end;
end.