AuraTrader Sample
This commit is contained in:
+33
-12
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user