Ignore:
Timestamp:
Apr 14, 2011, 12:47:57 PM (14 years ago)
Author:
george
Message:
  • Modified: MicroThreading replaced by TListedThread classic thread implementation.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • PinConnection/UCommProtocol.pas

    r222 r231  
    66
    77uses
    8   Classes, SysUtils, UVarBlockSerializer, syncobjs, UCommPin, UMicroThreading,
    9   UDebugLog, UStreamHelper, StopWatch, SpecializedList, UCommon, UPlatform,
     8  Classes, SysUtils, UVarBlockSerializer, syncobjs, UCommPin, UThreading,
     9  UDebugLog, UStreamHelper, StopWatch, SpecializedList, UCommon,
    1010  DateUtils;
    1111
     
    2626  private
    2727    RepeatCounter: integer;
    28     ReceiveEvent: TMicroThreadEvent;
     28    ReceiveEvent: TSimpleEvent;
    2929    Request: TStreamHelper;
    3030    ResponseParameters: TVarBlockIndexed;
    3131    TransmitTime: TDateTime;
    3232  public
    33     Lock: TMicroThreadCriticalSection;
     33    Lock: TCriticalSection;
    3434    SequenceNumber: Integer;
    3535    ResponseCode: Integer;
     
    5151    SequenceNumber: integer;
    5252    Parent: TCommProtocol;
    53     Lock: TMicroThreadCriticalSection;
     53    Lock: TCriticalSection;
    5454    procedure Add(Session: TDeviceProtocolSession);
    5555    function GetBySequence(Sequence: integer): TDeviceProtocolSession;
     
    6565  { TRetransmitCheckThread }
    6666
    67   TRetransmitCheckThread = class(TMicroThread)
     67  TRetransmitCheckThread = class(TListedThread)
    6868  public
    6969    Parent: TCommProtocol;
     
    8282    OnAfterRequest: TAfterRequest;
    8383    RetransmitThread: TRetransmitCheckThread;
    84     procedure DataReceive(Sender: TCommPin; Stream: TStream);
    8584    procedure HandleRequest(Stream: TStream);
    8685    procedure SetActive(const AValue: Boolean);
     
    9897    LastCommandResponseTime: TDateTime;
    9998    LastLatency: TDateTime;
     99    procedure DataReceive(Sender: TCommPin; Stream: TStream); virtual;
    100100    procedure SendCommand(Command: array of integer;
    101101      ResponseParameters: TVarBlockIndexed = nil;
     
    153153                if TestIndex(4) then CommandError := ReadVarUInt(4)
    154154                  else CommandError := 0;
    155                 Latency := NowPrecise - TransmitTime;
     155                Latency := Now - TransmitTime;
    156156                ReceiveEvent.SetEvent;
    157157              finally
     
    254254    RetransmitThread := TRetransmitCheckThread.Create(True);
    255255    with RetransmitThread do begin
    256       CheckPeriod := 100;
     256      CheckPeriod := 100; // ms
    257257      Parent := Self;
    258258      FreeOnTerminate := False;
     
    296296        // Wait for free remote buffer
    297297        while (RemoteBufferUsed + Request.Size) > RemoteBufferSize do
    298           MTSleep(1 * OneMillisecond);
     298          Sleep(1);
    299299
    300300        //StopWatch.Start;
    301         TransmitTime := NowPrecise;
     301        TransmitTime := Now;
    302302        Pin.Send(Request);
    303303      finally
     
    311311          Sessions.Lock.Release;
    312312        end;
    313         while ReceiveEvent.WaitFor(10 * OneMillisecond) = wrTimeout do begin
     313        while ReceiveEvent.WaitFor(10) = wrTimeout do begin
    314314          if Timeouted then
    315315            raise ECommTimeout.Create(SResponseTimeout);
     
    320320          raise ECommResponseCodeError.Create(Format(SResponseError, [CommandIndex.Implode('.', IntToStr), IntToStr(ResponseCode)]));
    321321        end;
    322         LastCommandResponseTime := NowPrecise;
     322        LastCommandResponseTime := Now;
    323323        LastLatency := Latency;
    324324      finally
     
    365365begin
    366366  ResponseCode := 0;
    367   Lock := TMicroThreadCriticalSection.Create;
    368   ReceiveEvent := TMicroThreadEvent.Create;
    369   ReceiveEvent.AutoReset := False;
     367  Lock := TCriticalSection.Create;
     368  ReceiveEvent := TSimpleEvent.Create;
     369  //ReceiveEvent.ManualReset := True;
    370370  Request := TStreamHelper.Create;
    371371  ResponseParameters := nil;
     
    396396      try
    397397        Lock.Release;
    398         MTSleep(1 * OneMillisecond);
     398        Sleep(1);
    399399      finally
    400400        Lock.Acquire;
     
    434434begin
    435435  inherited Create;
    436   Lock := TMicroThreadCriticalSection.Create;
     436  Lock := TCriticalSection.Create;
    437437end;
    438438
     
    478478          try
    479479            Session.Lock.Acquire;
    480             if (TransmitTime > 0) and (NowPrecise > (TransmitTime + RetransmitTimeout)) then begin
     480            if (TransmitTime > 0) and (Now > (TransmitTime + RetransmitTimeout)) then begin
    481481              if RepeatCounter < RetransmitRepeatCount then begin
    482482                Pin.Send(Request);
    483                 TransmitTime := NowPrecise;
     483                TransmitTime := Now;
    484484                Inc(RepeatCounter);
    485485                Inc(RetransmitTotalCount);
     
    498498
    499499    if not Terminated then
    500       MTSleep(CheckPeriod * OneMillisecond);
     500      Sleep(CheckPeriod);
    501501  until Terminated;
    502502end;
Note: See TracChangeset for help on using the changeset viewer.