Data file handling
This commit is contained in:
+23
-7
@@ -3,7 +3,8 @@ unit Myc.Signals;
|
||||
interface
|
||||
|
||||
uses
|
||||
System.SysUtils;
|
||||
System.SysUtils,
|
||||
System.SyncObjs;
|
||||
|
||||
type
|
||||
TSignal = record
|
||||
@@ -136,6 +137,8 @@ type
|
||||
strict private
|
||||
class var
|
||||
FNull: ILatch;
|
||||
FQueueGate: TLatch;
|
||||
FQueueLock: TSpinLock;
|
||||
class constructor ClassCreate;
|
||||
|
||||
private
|
||||
@@ -150,7 +153,8 @@ type
|
||||
|
||||
class function CreateLatch(Count: Integer): TLatch; static;
|
||||
|
||||
class function Enqueue(var Gate: TLatch; Count: Integer = 1): TState; static;
|
||||
class function Enqueue(var Gate: TLatch): TState; overload; static;
|
||||
class function Enqueue: TState; overload; static;
|
||||
|
||||
class property Null: ILatch read FNull;
|
||||
|
||||
@@ -390,6 +394,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);
|
||||
end;
|
||||
|
||||
constructor TLatch.Create(const ALatch: TLatch.ILatch);
|
||||
@@ -407,12 +412,23 @@ begin
|
||||
Result := FNull;
|
||||
end;
|
||||
|
||||
class function TLatch.Enqueue(var Gate: TLatch; Count: Integer = 1): TState;
|
||||
class function TLatch.Enqueue(var Gate: TLatch): TState;
|
||||
begin
|
||||
var gateState := Gate.State;
|
||||
Gate := TMycLatch.Create(Count);
|
||||
gateState.Subscribe(Gate);
|
||||
exit(Gate.State);
|
||||
var Latch: TLatch.ILatch := TMycLatch.Create(1);
|
||||
|
||||
FQueueLock.Enter;
|
||||
try
|
||||
Gate.State.Subscribe(Latch);
|
||||
Gate := Latch;
|
||||
Result := Latch.State;
|
||||
finally
|
||||
FQueueLock.Exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
class function TLatch.Enqueue: TState;
|
||||
begin
|
||||
Result := Enqueue(FQueueGate);
|
||||
end;
|
||||
|
||||
function TLatch.GetState: TState;
|
||||
|
||||
Reference in New Issue
Block a user