Ignore:
Timestamp:
Jan 26, 2011, 7:12:08 PM (14 years ago)
Author:
george
Message:
  • Moved: Global function with platform depending implementation moved to UPlatform unit.
  • Modifed: Demo form restructuralized to tabs with separate pages.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/UMainForm.pas

    r148 r149  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ExtCtrls, Spin, UMicroThreading, Coroutine, DateUtils;
     9  ComCtrls, ExtCtrls, Spin, UMicroThreading, Coroutine, DateUtils, UPlatform;
    1010
    1111type
     
    1414
    1515  TMainForm = class(TForm)
    16     ButtonSchedulerStartStop: TButton;
    1716    Button2: TButton;
    1817    ButtonAddWorkers: TButton;
     18    ButtonClearMicroThreads: TButton;
    1919    ButtonGetMaxThread: TButton;
     20    ButtonSchedulerStartStop: TButton;
    2021    ButtonShowThreadId: TButton;
    21     ButtonClearMicroThreads: TButton;
     22    GroupBox1: TGroupBox;
     23    GroupBox2: TGroupBox;
    2224    Label1: TLabel;
     25    Label10: TLabel;
    2326    Label2: TLabel;
    2427    Label3: TLabel;
     
    2629    Label5: TLabel;
    2730    Label6: TLabel;
     31    Label7: TLabel;
     32    Label8: TLabel;
     33    Label9: TLabel;
    2834    ListView1: TListView;
    2935    Memo1: TMemo;
     36    PageControl1: TPageControl;
    3037    SpinEdit1: TSpinEdit;
    3138    SpinEdit2: TSpinEdit;
    32     Timer1: TTimer;
     39    TabSheet1: TTabSheet;
     40    TabSheet2: TTabSheet;
     41    TabSheet3: TTabSheet;
     42    TimerRedraw: TTimer;
     43    TimerSchedulerStart: TTimer;
    3344    procedure ButtonSchedulerStartStopClick(Sender: TObject);
    3445    procedure Button2Click(Sender: TObject);
     
    4051    procedure FormCreate(Sender: TObject);
    4152    procedure FormDestroy(Sender: TObject);
     53    procedure FormShow(Sender: TObject);
    4254    procedure ListView1Data(Sender: TObject; Item: TListItem);
    4355    procedure SpinEdit2Change(Sender: TObject);
    44     procedure Timer1Timer(Sender: TObject);
     56    procedure TimerRedrawTimer(Sender: TObject);
     57    procedure TimerSchedulerStartTimer(Sender: TObject);
    4558  private
    4659    procedure Worker(MicroThread: TMicroThread);
     
    6578  DoubleBuffered := True;
    6679  ListView1.DoubleBuffered := True;
    67   Label6.Caption := IntToStr(Scheduler.GetCPUCoreCount);
     80  Label6.Caption := IntToStr(GetLogicalProcessorCount);
    6881end;
    6982
     
    185198end;
    186199
     200procedure TMainForm.FormShow(Sender: TObject);
     201begin
     202end;
     203
    187204procedure TMainForm.ListView1Data(Sender: TObject; Item: TListItem);
    188205begin
     
    198215      Item.SubItems.Add(FloatToStr(ExecutionTime));
    199216      Item.SubItems.Add(IntToStr(Trunc(Completion * 100)) + '%');
     217      Item.SubItems.Add(IntToStr(StackUsed));
    200218    end;
    201219  finally
     
    209227end;
    210228
    211 procedure TMainForm.Timer1Timer(Sender: TObject);
     229procedure TMainForm.TimerRedrawTimer(Sender: TObject);
    212230begin
    213231  ListView1.Items.Count := Scheduler.MicroThreadCount;
    214232  ListView1.Items[-1];
    215233  ListView1.Refresh;
    216   Label2.Caption := DateTimeToStr(Scheduler.GetNow) + ' ' +
    217     FloatToStr(Frac(Scheduler.GetNow / OneSecond));
     234  Label2.Caption := DateTimeToStr(NowPrecise) + ' ' +
     235    FloatToStr(Frac(NowPrecise / OneSecond));
     236  Label9.Caption := IntToStr(Scheduler.ThreadPoolCount);
     237  Label10.Caption := IntToStr(Scheduler.MicroThreadCount);
     238end;
     239
     240procedure TMainForm.TimerSchedulerStartTimer(Sender: TObject);
     241begin
     242  TimerSchedulerStart.Enabled := False;
     243  ButtonAddWorkers.Click;
     244  ButtonSchedulerStartStop.Click;
    218245end;
    219246
     
    226253begin
    227254  with MicroThread do begin
    228     Memo1.Lines.Add('Worker ' + IntToStr(Id));
     255    //Memo1.Lines.Add('Worker ' + IntToStr(Id));
    229256    for I := 0 to TotalSteps - 1 do begin
    230257      Q := 0;
    231       while Q < 1000000 do Inc(Q);
     258      while Q < 10000 do Inc(Q);
    232259      //Memo1.Lines.Add(IntToStr(Id) + ': ' + IntToStr(I) + ' ' +
    233260      //  FloatToStr(ExecutionTime));
Note: See TracChangeset for help on using the changeset viewer.