Changeset 414 for trunk/Packages/PinConnection/CommThread.pas
- Timestamp:
- Jan 10, 2025, 4:24:19 PM (7 hours ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/PinConnection/CommThread.pas
r340 r414 12 12 TReceiveDataEvent = procedure(Stream: TMemoryStream) of object; 13 13 14 { TCommThreadReceive Thread }15 16 TCommThreadReceive Thread = class(TTermThread)14 { TCommThreadReceiveDataThread } 15 16 TCommThreadReceiveDataThread = class(TTermThread) 17 17 public 18 18 Parent: TCommThread; … … 24 24 end; 25 25 26 { TCommThreadReceiveStatusThread } 27 28 TCommThreadReceiveStatusThread = class(TTermThread) 29 public 30 Parent: TCommThread; 31 Stream: TBinarySerializer; 32 procedure Execute; override; 33 constructor Create(CreateSuspended: Boolean; 34 const StackSize: SizeUInt = DefaultStackSize); 35 destructor Destroy; override; 36 end; 37 26 38 { TCommThread } 27 39 … … 29 41 private 30 42 //FOnReceiveData: TReceiveDataEvent; 31 FReceiveThread: TCommThreadReceiveThread; 43 FReceiveDataThread: TCommThreadReceiveDataThread; 44 FReceiveStatusThread: TCommThreadReceiveStatusThread; 32 45 FInputBuffer: TBinarySerializer; 33 46 FInputBufferLock: TCriticalSection; … … 91 104 92 105 if AValue then begin 93 FReceiveThread := TCommThreadReceiveThread.Create(True); 94 FReceiveThread.FreeOnTerminate := False; 95 FReceiveThread.Parent := Self; 96 FReceiveThread.Name := 'CommThread'; 97 FReceiveThread.Start; 106 FReceiveDataThread := TCommThreadReceiveDataThread.Create(True); 107 FReceiveDataThread.FreeOnTerminate := False; 108 FReceiveDataThread.Parent := Self; 109 FReceiveDataThread.Name := 'CommThreadData'; 110 FReceiveDataThread.Start; 111 112 FReceiveStatusThread := TCommThreadReceiveStatusThread.Create(True); 113 FReceiveStatusThread.FreeOnTerminate := False; 114 FReceiveStatusThread.Parent := Self; 115 FReceiveStatusThread.Name := 'CommThreadStatus'; 116 FReceiveStatusThread.Start; 98 117 end else begin 99 FreeAndNil(FReceiveThread); 118 FreeAndNil(FReceiveDataThread); 119 FreeAndNil(FReceiveStatusThread); 100 120 end; 101 121 inherited; … … 134 154 end; 135 155 136 { TCommThreadReceiveThread } 137 138 procedure TCommThreadReceiveThread.Execute; 139 var 140 TempStatus: Integer; 141 DoSleep: Boolean; 156 { TCommThreadReceiveDataThread } 157 158 procedure TCommThreadReceiveDataThread.Execute; 142 159 begin 143 160 with Parent do 144 161 repeat 145 DoSleep := True;146 162 // Check if new data arrived 147 if FDataAvailable.WaitFor(0) = wrSignaled then begin 148 DoSleep := False; 163 if FDataAvailable.WaitFor(100) = wrSignaled then begin 149 164 try 150 165 FInputBufferLock.Acquire; … … 157 172 Pin.Send(Stream.List); 158 173 end; 159 174 until Terminated; 175 end; 176 177 constructor TCommThreadReceiveDataThread.Create(CreateSuspended: Boolean; 178 const StackSize: SizeUInt); 179 begin 180 inherited; 181 Stream := TBinarySerializer.Create; 182 Stream.List := TListByte.Create; 183 Stream.OwnsList := True; 184 end; 185 186 destructor TCommThreadReceiveDataThread.Destroy; 187 begin 188 FreeAndNil(Stream); 189 inherited; 190 end; 191 192 { TCommThreadReceiveStatusThread } 193 194 procedure TCommThreadReceiveStatusThread.Execute; 195 var 196 TempStatus: Integer; 197 begin 198 with Parent do 199 repeat 160 200 // Check if state changed 161 if FStatusEvent.WaitFor(0) = wrSignaled then begin 162 DoSleep := False; 201 if FStatusEvent.WaitFor(100) = wrSignaled then begin 163 202 try 164 203 FInputBufferLock.Acquire; … … 170 209 Pin.Status := TempStatus; 171 210 end; 172 if not Terminated and DoSleep then begin173 Sleep(1);174 end;175 211 until Terminated; 176 212 end; 177 213 178 constructor TCommThreadReceive Thread.Create(CreateSuspended: Boolean;214 constructor TCommThreadReceiveStatusThread.Create(CreateSuspended: Boolean; 179 215 const StackSize: SizeUInt); 180 216 begin … … 185 221 end; 186 222 187 destructor TCommThreadReceive Thread.Destroy;223 destructor TCommThreadReceiveStatusThread.Destroy; 188 224 begin 189 225 FreeAndNil(Stream);
Note:
See TracChangeset
for help on using the changeset viewer.