Ignore:
Timestamp:
Jan 27, 2011, 2:15:57 PM (14 years ago)
Author:
george
Message:
  • Add: Not completed event signaling support.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/Demo/UMainForm.pas

    r153 r154  
    77uses
    88  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    9   ComCtrls, ExtCtrls, Spin, UMicroThreading, Coroutine, DateUtils, UPlatform;
     9  ComCtrls, ExtCtrls, Spin, UMicroThreading, DateUtils, UPlatform;
    1010
    1111type
     
    6767    procedure Worker(MicroThread: TMicroThread);
    6868    procedure WorkerDoWrite;
     69    procedure WorkerSubRoutine;
    6970  public
    7071    Iterations: Integer;
    71     Scheduler: TMicroThreadScheduler;
    7272  end;
    7373
     
    8585procedure TMainForm.FormCreate(Sender: TObject);
    8686begin
    87   Scheduler := TMicroThreadScheduler.Create;
    8887  DoubleBuffered := True;
    8988  ListView1.DoubleBuffered := True;
     
    9796  if ButtonSchedulerStartStop.Caption = 'Start scheduler' then begin
    9897    ButtonSchedulerStartStop.Caption := 'Stop scheduler';
    99     Scheduler.ThreadPoolSize := SpinEdit2.Value;
    100     Scheduler.Active := True;
     98    MainScheduler.ThreadPoolSize := SpinEdit2.Value;
     99    MainScheduler.Active := True;
    101100  end else begin
    102101    ButtonSchedulerStartStop.Caption := 'Start scheduler';
    103     Scheduler.Active := False;
     102    MainScheduler.Active := False;
    104103  end;
    105104end;
     
    169168  //Scheduler.FMicroThreads.Clear;
    170169  for I := 0 to SpinEdit1.Value - 1 do
    171     Scheduler.AddMethod(Worker);
     170    MainScheduler.AddMethod(Worker);
    172171end;
    173172
     
    197196begin
    198197  try
    199     Scheduler.MicroThreadsLock.Acquire;
    200     Scheduler.MicroThreads.Clear;
     198    MainScheduler.MicroThreadsLock.Acquire;
     199    MainScheduler.MicroThreads.Clear;
    201200  finally
    202     Scheduler.MicroThreadsLock.Release;
     201    MainScheduler.MicroThreadsLock.Release;
    203202  end;
    204203end;
     
    206205procedure TMainForm.CheckBoxUseMainThreadChange(Sender: TObject);
    207206begin
    208   Scheduler.UseMainThread := CheckBoxUseMainThread.Checked;
     207  MainScheduler.UseMainThread := CheckBoxUseMainThread.Checked;
    209208end;
    210209
    211210procedure TMainForm.FormClose(Sender: TObject; var CloseAction: TCloseAction);
    212211begin
    213   Scheduler.Active := False;
     212  MainScheduler.Active := False;
    214213end;
    215214
    216215procedure TMainForm.FormDestroy(Sender: TObject);
    217216begin
    218   Scheduler.Free;
     217  MainScheduler.Free;
    219218end;
    220219
     
    227226begin
    228227  try
    229     Scheduler.MicroThreadsLock.Acquire;
    230     if Item.Index < Scheduler.MicroThreads.Count then
    231     with TMicroThread(Scheduler.MicroThreads[Item.Index]) do begin
     228    MainScheduler.MicroThreadsLock.Acquire;
     229    if Item.Index < MainScheduler.MicroThreads.Count then
     230    with TMicroThread(MainScheduler.MicroThreads[Item.Index]) do begin
    232231      Item.Caption := IntToStr(Id);
    233232      Item.SubItems.Add(Name);
     
    240239    end;
    241240  finally
    242     Scheduler.MicroThreadsLock.Release;
     241    MainScheduler.MicroThreadsLock.Release;
    243242  end;
    244243end;
     
    246245procedure TMainForm.SpinEdit2Change(Sender: TObject);
    247246begin
    248   Scheduler.ThreadPoolSize := SpinEdit2.Value;
     247  MainScheduler.ThreadPoolSize := SpinEdit2.Value;
    249248end;
    250249
     
    256255procedure TMainForm.TimerRedrawTimer(Sender: TObject);
    257256begin
    258   if ListView1.Items.Count <> Scheduler.MicroThreadCount then
    259     ListView1.Items.Count := Scheduler.MicroThreadCount;
     257  if ListView1.Items.Count <> MainScheduler.MicroThreadCount then
     258    ListView1.Items.Count := MainScheduler.MicroThreadCount;
    260259  ListView1.Items[-1];
    261260  ListView1.Refresh;
    262261  Label2.Caption := DateTimeToStr(NowPrecise) + ' ' +
    263262    FloatToStr(Frac(NowPrecise / OneSecond));
    264   Label9.Caption := IntToStr(Scheduler.ThreadPoolCount);
    265   Label10.Caption := IntToStr(Scheduler.MicroThreadCount);
     263  Label9.Caption := IntToStr(MainScheduler.ThreadPoolCount);
     264  Label10.Caption := IntToStr(MainScheduler.MicroThreadCount);
    266265end;
    267266
     
    271270  ButtonAddWorkers.Click;
    272271  ButtonSchedulerStartStop.Click;
     272end;
     273
     274procedure TMainForm.WorkerSubRoutine;
     275begin
     276  MTSleep(1 * OneMillisecond);
    273277end;
    274278
     
    287291      //  FloatToStr(ExecutionTime));
    288292      Completion := I / Iterations;
    289       //Sleep(1 * Id * OneMillisecond);
     293      //MTSleep(1 * Id * OneMillisecond);
    290294      Yield;
     295      WorkerSubRoutine;
    291296    end;
    292297  end;
Note: See TracChangeset for help on using the changeset viewer.