Writeables revised
Read-ahead for DataStream Processing
This commit is contained in:
+27
-3
@@ -10,9 +10,10 @@ uses
|
||||
|
||||
type
|
||||
TMycNullMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable)
|
||||
protected
|
||||
private
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
end;
|
||||
|
||||
TMycMutableBase<T> = class(TInterfacedObject, TMutable<T>.IMutable)
|
||||
@@ -20,6 +21,7 @@ type
|
||||
FChanged: TEvent;
|
||||
FChangeState: TSignal.TSubscription;
|
||||
function GetChanged: TSignal;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
protected
|
||||
function GetValue: T; virtual; abstract;
|
||||
public
|
||||
@@ -36,13 +38,14 @@ type
|
||||
constructor Create(const AChanged: TSignal; const AProc: TFunc<T>);
|
||||
end;
|
||||
|
||||
TMycWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TWriteable<T>.IWriteable)
|
||||
TMycWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TMutable<T>.IWriter)
|
||||
private
|
||||
FValue: T;
|
||||
FChanged: TEvent;
|
||||
protected
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
public
|
||||
constructor Create(const AValue: T);
|
||||
procedure SetValue(const Value: T);
|
||||
@@ -77,7 +80,7 @@ type
|
||||
constructor Create(const AChanged: TSignal.ISignal; const AProc: TFunc<T>);
|
||||
end;
|
||||
|
||||
TMycProtectedWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TWriteable<T>.IWriteable)
|
||||
TMycProtectedWriteableMutable<T> = class(TInterfacedObject, TMutable<T>.IMutable, TMutable<T>.IWriter)
|
||||
private
|
||||
FValue: T;
|
||||
FChanged: TEvent;
|
||||
@@ -85,6 +88,7 @@ type
|
||||
protected
|
||||
function GetChanged: TSignal;
|
||||
function GetValue: T;
|
||||
function GetWriter: TMutable<T>.IWriter;
|
||||
procedure Lock; inline;
|
||||
procedure Release; inline;
|
||||
public
|
||||
@@ -106,6 +110,11 @@ begin
|
||||
Result := Default(T);
|
||||
end;
|
||||
|
||||
function TMycNullMutable<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
{ TMycMutableBase<T> }
|
||||
|
||||
constructor TMycMutableBase<T>.Create(const AChanged: TSignal);
|
||||
@@ -126,6 +135,11 @@ begin
|
||||
Result := FChanged.Signal;
|
||||
end;
|
||||
|
||||
function TMycMutableBase<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := nil;
|
||||
end;
|
||||
|
||||
{ TMycWriteableMutable<T> }
|
||||
|
||||
constructor TMycWriteableMutable<T>.Create(const AValue: T);
|
||||
@@ -145,6 +159,11 @@ begin
|
||||
Result := FValue;
|
||||
end;
|
||||
|
||||
function TMycWriteableMutable<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := Self;
|
||||
end;
|
||||
|
||||
procedure TMycWriteableMutable<T>.SetValue(const Value: T);
|
||||
begin
|
||||
FValue := Value;
|
||||
@@ -244,6 +263,11 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
function TMycProtectedWriteableMutable<T>.GetWriter: TMutable<T>.IWriter;
|
||||
begin
|
||||
Result := Self;
|
||||
end;
|
||||
|
||||
procedure TMycProtectedWriteableMutable<T>.Lock;
|
||||
begin
|
||||
while AtomicExchange(FLock, 1) = 1 do
|
||||
|
||||
Reference in New Issue
Block a user