Changeset 6 for trunk/Platform/Base
- Timestamp:
- Nov 23, 2014, 11:17:11 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Platform/Base/UPlatformBase.pas
r5 r6 6 6 7 7 uses 8 Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory; 8 Classes, SysUtils, UFileSystem, UKernel, syncobjs, UThreadEx, UMemory, 9 DateUtils; 9 10 10 11 type … … 32 33 33 34 TBaseScheduler = class(TScheduler) 35 procedure SwitchNext; override; 36 function GetCurrentTask: TTask; override; 34 37 function AddTask(Name: string; EntryPoint: TTaskEvent): TTask; override; 35 38 constructor Create; override; … … 106 109 { TBaseScheduler } 107 110 111 procedure TBaseScheduler.SwitchNext; 112 var 113 Task: TTask; 114 Duration: TDateTime; 115 begin 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; 123 end; 124 125 function TBaseScheduler.GetCurrentTask: TTask; 126 var 127 I: Integer; 128 begin 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; 134 end; 135 108 136 function TBaseScheduler.AddTask(Name: string; EntryPoint: TTaskEvent): TTask; 109 137 var
Note:
See TracChangeset
for help on using the changeset viewer.