Changeset 6 for trunk/Platform/Base


Ignore:
Timestamp:
Nov 23, 2014, 11:17:11 PM (10 years ago)
Author:
chronos
Message:
  • Added: Preparation for support for IPC messaging.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Platform/Base/UPlatformBase.pas

    r5 r6  
    66
    77uses
    8   Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory;
     8  Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory,
     9  DateUtils;
    910
    1011type
     
    3233
    3334  TBaseScheduler = class(TScheduler)
     35    procedure SwitchNext; override;
     36    function GetCurrentTask: TTask; override;
    3437    function AddTask(Name: string; EntryPoint: TTaskEvent): TTask; override;
    3538    constructor Create; override;
     
    106109{ TBaseScheduler }
    107110
     111procedure TBaseScheduler.SwitchNext;
     112var
     113  Task: TTask;
     114  Duration: TDateTime;
     115begin
     116  Task := GetCurrentTask;
     117  if Task.State = tsWaiting then begin
     118    if Task.WaitReason = wrSleep then begin
     119      Duration := (Task.WakeUpTime - Now) / OneMillisecond;
     120      if Duration > 0 then SysUtils.Sleep(Trunc(Duration));
     121    end;
     122  end;
     123end;
     124
     125function TBaseScheduler.GetCurrentTask: TTask;
     126var
     127  I: Integer;
     128begin
     129  I := 0;
     130  while (I < Tasks.Count) and (TBaseTask(Tasks[I]).Thread.ThreadID <> ThreadID) do
     131    Inc(I);
     132  if I < Tasks.Count then Result := TBaseTask(Tasks[I])
     133    else Result := nil;
     134end;
     135
    108136function TBaseScheduler.AddTask(Name: string; EntryPoint: TTaskEvent): TTask;
    109137var
Note: See TracChangeset for help on using the changeset viewer.