Changeset 231


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

Legend:

Unmodified
Added
Removed
  • PinConnection/PinConnection.lpk

    r163 r231  
    66    <Author Value="Chronos"/>
    77    <CompilerOptions>
    8       <Version Value="10"/>
     8      <Version Value="9"/>
    99      <PathDelim Value="\"/>
    1010      <SearchPaths>
     
    5757    </Files>
    5858    <Type Value="RunAndDesignTime"/>
    59     <RequiredPkgs Count="5">
     59    <RequiredPkgs Count="4">
    6060      <Item1>
    61         <PackageName Value="MicroThreading"/>
     61        <PackageName Value="synapse"/>
    6262      </Item1>
    6363      <Item2>
    64         <PackageName Value="synapse"/>
     64        <PackageName Value="Common"/>
    6565      </Item2>
    6666      <Item3>
    67         <PackageName Value="Common"/>
     67        <PackageName Value="CoolStreaming"/>
    6868      </Item3>
    6969      <Item4>
    70         <PackageName Value="CoolStreaming"/>
    71       </Item4>
    72       <Item5>
    7370        <PackageName Value="FCL"/>
    7471        <MinVersion Major="1" Valid="True"/>
    75       </Item5>
     72      </Item4>
    7673    </RequiredPkgs>
    7774    <UsageOptions>
  • 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;
  • PinConnection/UCommSerialPort.pas

    r171 r231  
    66
    77uses
    8   Classes, USerialPort, UCommPin, SysUtils, UMicroThreading, DateUtils,
     8  Classes, USerialPort, UCommPin, SysUtils, DateUtils,
    99  SyncObjs;
    1010
     
    1515    procedure ReceiveData(Stream: TMemoryStream);
    1616  public
    17     Lock: TMicroThreadCriticalSection;
     17    Lock: TCriticalSection;
    1818    Pin: TCommPin;
    1919    destructor Destroy; override;
     
    3535begin
    3636  inherited;
    37   Lock := TMicroThreadCriticalSection.Create;
     37  Lock := TCriticalSection.Create;
    3838  Pin := TCommPin.Create;
    3939  Pin.OnReceive := Receive;
     
    6060    end;
    6161    if Stream.Position <> Stream.Size then
    62       MTSleep(1 * OneMillisecond);
     62      Sleep(1);
    6363  until Stream.Position = Stream.Size;
    6464end;
  • PinConnection/UCommSocket.pas

    r163 r231  
    66
    77uses
    8   Classes, SysUtils, blcksock, UCommPin, UCommon, UMicroThreading,
     8  Classes, SysUtils, blcksock, UCommPin, UCommon, UThreading,
    99  DateUtils;
    1010
     
    1616  { TCommSocketReceiveThread }
    1717
    18   TCommSocketReceiveThread = class(TMicroThread)
     18  TCommSocketReceiveThread = class(TListedThread)
    1919  public
    2020    Parent: TCommSocket;
     
    9494  InBufferUsed := 0;
    9595  with Parent do repeat
    96       if InBufferUsed = 0 then MTSleep(1 * OneMillisecond)
    97         else Yield;
     96      if InBufferUsed = 0 then Sleep(1);
     97        //else Yield;
    9898      if Assigned(Socket) then
    9999      with Socket do
  • PinConnection/UCommThread.pas

    r222 r231  
    77uses
    88  Classes, SysUtils, blcksock, UCommPin, SyncObjs, UStreamHelper, UCommon,
    9   UMicroThreading, DateUtils;
     9  DateUtils, UThreading;
    1010
    1111type
     
    1616  { TCommThreadReceiveThread }
    1717
    18   TCommThreadReceiveThread = class(TMicroThread)
     18  TCommThreadReceiveThread = class(TListedThread)
    1919  public
    2020    Parent: TCommThread;
     
    3434    FReceiveThread: TCommThreadReceiveThread;
    3535    FInputBuffer: TMemoryStream;
    36     FInputBufferLock: TMicroThreadCriticalSection;
    37     FDataAvailable: TMicroThreadEvent;
     36    FInputBufferLock: TCriticalSection;
     37    FDataAvailable: TEvent;
    3838    procedure ReceiveData(Sender: TCommPin; Stream: TStream);
    3939    procedure ExtReceiveData(Sender: TCommPin; Stream: TStream);
     
    9393  inherited Create;
    9494  FInputBuffer := TMemoryStream.Create;
    95   FInputBufferLock := TMicroThreadCriticalSection.Create;
     95  FInputBufferLock := TCriticalSection.Create;
    9696  Ext := TCommPin.Create;
    9797  Ext.OnReceive := ExtReceiveData;
    9898  Pin := TCommPin.Create;
    9999  Pin.OnReceive := ReceiveData;
    100   FDataAvailable := TMicroThreadEvent.Create;
     100  FDataAvailable := TSimpleEvent.Create;
    101101end;
    102102
     
    122122    with Parent do
    123123    repeat
    124       if FDataAvailable.WaitFor(1 * OneMillisecond) = wrSignaled then begin
     124      if FDataAvailable.WaitFor(1) = wrSignaled then begin
    125125      try
    126126        FInputBufferLock.Acquire;
     
    132132        FInputBufferLock.Release;
    133133      end;
    134       end else Yield;
     134      end; // else Yield;
    135135    until Terminated;
    136136  finally
  • PinConnection/UPacketBurst.pas

    r171 r231  
    77uses
    88  Classes, UCommPin, SyncObjs, UStreamHelper, UCommon, SysUtils,
    9   UMicroThreading, DateUtils;
     9  DateUtils;
    1010
    1111type
    1212  TPacketBurst = class;
    1313
    14   TPacketBurstSendThread = class(TMicroThread)
     14  TPacketBurstSendThread = class(TThread)
    1515    PacketBurst: TPacketBurst;
    1616    procedure Execute; override;
     
    2222  private
    2323    FActive: Boolean;
    24     SendThreadEvent: TMicroThreadEvent;
     24    SendThreadEvent: TEvent;
    2525    SendThread: TPacketBurstSendThread;
    2626    SendStreamLock: TCriticalSection;
     
    3131    procedure SetActive(const AValue: Boolean);
    3232  public
    33     SendPeriod: TDateTime;
     33    SendPeriod: Integer;
    3434    SendBurstSize: Integer;
    3535    PacketSinglePin: TCommPin;
     
    5050  PacketBurstPin := TCommPin.Create;
    5151  PacketBurstPin.OnReceive := PacketBurstReceive;
    52   SendThreadEvent := TMicroThreadEvent.Create;
    53   SendPeriod := OneMillisecond;
     52  SendThreadEvent := TSimpleEvent.Create;
     53  SendPeriod := 1;
    5454end;
    5555
     
    9393    SendThread.FreeOnTerminate := False;
    9494    SendThread.PacketBurst := Self;
    95     SendThread.Name := 'PacketBurst';
     95    //SendThread.Name := 'PacketBurst';
    9696    SendThread.Start;
    9797  end else begin
  • PinConnection/USerialPort.pas

    r163 r231  
    66
    77uses
    8   Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, UMicroThreading,
     8  Classes, SysUtils, SynaSer, StdCtrls, Dialogs, UCommon, UThreading,
    99  DateUtils;
    1010
     
    2323  { TSerialPortReceiveThread }
    2424
    25   TSerialPortReceiveThread = class(TMicroThread)
     25  TSerialPortReceiveThread = class(TListedThread)
    2626  public
    2727    Parent: TSerialPort;
     
    292292  InBufferUsed := 0;
    293293  with Parent do repeat
    294       if InBufferUsed = 0 then MTSleep(1 * OneMillisecond)
    295         else Yield;
     294      if InBufferUsed = 0 then Sleep(1);
     295        //else Yield;
    296296      if Active then begin
    297297        InBufferUsed := WaitingData;
Note: See TracChangeset for help on using the changeset viewer.