AuraTrader Sample

This commit is contained in:
Michael Schimmel
2025-06-17 21:49:09 +02:00
parent f81337c98d
commit a9aff8c41a
13 changed files with 2093 additions and 306 deletions
+33 -12
View File
@@ -3,8 +3,7 @@ unit Myc.Signals;
interface
uses
System.SysUtils,
System.SyncObjs;
System.SysUtils;
type
TSignal = record
@@ -137,8 +136,7 @@ type
strict private
class var
FNull: ILatch;
FQueueGate: TLatch;
FQueueLock: TSpinLock;
FQueueLock: Integer;
class constructor ClassCreate;
private
@@ -153,8 +151,8 @@ type
class function CreateLatch(Count: Integer): TLatch; static;
class function Enqueue(var Gate: TLatch): TState; overload; static;
class function Enqueue: TState; overload; static;
class function Enqueue1(var Gate: TLatch): TState; overload; static;
function Enqueue: TState; overload;
class property Null: ILatch read FNull;
@@ -394,7 +392,7 @@ class constructor TLatch.ClassCreate;
begin
// Create a singleton null latch instance that is initially (and always) set.
FNull := TMycNullLatch.Create;
FQueueLock := TSpinLock.Create(false);
FQueueLock := 0;
end;
constructor TLatch.Create(const ALatch: TLatch.ILatch);
@@ -412,23 +410,46 @@ begin
Result := FNull;
end;
class function TLatch.Enqueue(var Gate: TLatch): TState;
class function TLatch.Enqueue1(var Gate: TLatch): TState;
begin
var Latch: TLatch.ILatch := TMycLatch.Create(1);
FQueueLock.Enter;
repeat
if FQueueLock > 0 then
begin
YieldProcessor;
continue;
end;
until AtomicCmpExchange(FQueueLock, 1, 0) = 0;
try
Gate.State.Subscribe(Latch);
Gate := Latch;
Result := Latch.State;
finally
FQueueLock.Exit;
AtomicDecrement(FQueueLock);
end;
end;
class function TLatch.Enqueue: TState;
function TLatch.Enqueue: TState;
begin
Result := Enqueue(FQueueGate);
var Latch: ILatch := TMycLatch.Create(1);
repeat
if FQueueLock > 0 then
begin
YieldProcessor;
continue;
end;
until AtomicCmpExchange(FQueueLock, 1, 0) = 0;
try
FLatch.State.Subscribe(Latch);
FLatch := Latch;
Result := FLatch.State;
finally
AtomicDecrement(FQueueLock);
end;
end;
function TLatch.GetState: TState;