Changeset 6
- Timestamp:
- Nov 23, 2014, 11:17:11 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 6 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Apps/UClock.pas
r5 r6 22 22 23 23 procedure TAppClock.Run(Task: TTask); 24 var 25 Message: TIPCMessage; 24 26 begin 27 Message := TIPCMessage.Create; 25 28 while not Task.Terminated do begin 26 29 API.WriteText('test'); 27 30 API.Sleep(OneSecond); 31 //API.ReadMessage(Message); 28 32 end; 33 Message.Free; 29 34 end; 30 35 -
trunk/ChronOS.lpi
r5 r6 71 71 </Item1> 72 72 </RequiredPackages> 73 <Units Count="1 2">73 <Units Count="14"> 74 74 <Unit0> 75 75 <Filename Value="ChronOS.lpr"/> … … 77 77 </Unit0> 78 78 <Unit1> 79 <Filename Value=" UFormMain.pas"/>80 <IsPartOfProject Value="True"/> 81 <ComponentName Value="Form 1"/>79 <Filename Value="Forms/UFormMain.pas"/> 80 <IsPartOfProject Value="True"/> 81 <ComponentName Value="FormMain"/> 82 82 <HasResources Value="True"/> 83 83 <ResourceBaseClass Value="Form"/> … … 134 134 <UnitName Value="UMemory"/> 135 135 </Unit11> 136 <Unit12> 137 <Filename Value="Forms/UFormTerminal.pas"/> 138 <IsPartOfProject Value="True"/> 139 <ComponentName Value="FormTerminal"/> 140 <ResourceBaseClass Value="Form"/> 141 <UnitName Value="UFormTerminal"/> 142 </Unit12> 143 <Unit13> 144 <Filename Value="UClasses.pas"/> 145 <IsPartOfProject Value="True"/> 146 <UnitName Value="UClasses"/> 147 </Unit13> 136 148 </Units> 137 149 </ProjectOptions> … … 143 155 <SearchPaths> 144 156 <IncludeFiles Value="$(ProjOutDir)"/> 145 <OtherUnitFiles Value="Apps;Platform/Base "/>157 <OtherUnitFiles Value="Apps;Platform/Base;Forms"/> 146 158 <UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/> 147 159 </SearchPaths> -
trunk/ChronOS.lpr
r5 r6 11 11 Interfaces, // this includes the LCL widgetset 12 12 Forms, SysUtils, UFormMain, UKernel, UFileSystem, UClock, UMemoryManager, UAPI, 13 UPlatformBase, UList, UApp, UThreadEx, UMemory ;13 UPlatformBase, UList, UApp, UThreadEx, UMemory, UFormTerminal, UClasses; 14 14 15 15 {$R *.res} … … 29 29 RequireDerivedFormResource := True; 30 30 Application.Initialize; 31 Application.CreateForm(TForm1, Form1); 31 Application.CreateForm(TFormMain, FormMain); 32 Application.CreateForm(TFormTerminal, FormTerminal); 32 33 Application.Run; 33 34 end. -
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 -
trunk/UAPI.pas
r4 r6 16 16 procedure WriteText(Text: string); 17 17 procedure Sleep(Time: TDateTime); 18 procedure ReadMessage(Message: TIPCMessage); 18 19 end; 19 20 … … 39 40 40 41 procedure TAPI.Sleep(Time: TDateTime); 42 var 43 Task: TTask; 41 44 begin 42 SysUtils.Sleep(Trunc(Time / OneMillisecond)); 45 Task := Kernel.Scheduler.GetCurrentTask; 46 Task.Sleep(Time); 47 end; 48 49 procedure TAPI.ReadMessage(Message: TIPCMessage); 50 var 51 Task: TTask; 52 begin 53 Task := Kernel.Scheduler.GetCurrentTask; 54 while Task.Messages.Count = 0 do Task.WaitForMessage; 43 55 end; 44 56 -
trunk/UKernel.pas
r5 r6 10 10 type 11 11 TTask = class; 12 TScheduler = class; 12 13 13 14 TTaskEvent = procedure(Task: TTask) of object; 14 15 15 TTaskState = (tsStopped, tsRunning, tsSuspended); 16 TTaskState = (tsStopped, tsRunning, tsSuspended, tsWaiting); 17 18 TIPCMessage = class 19 Name: string; 20 Action: string; 21 22 end; 23 24 TWaitReason = (wrSleep, wrMessage); 16 25 17 26 { TTask } 18 27 19 28 TTask = class(TNamedObject) 20 Name: string;29 Scheduler: TScheduler; 21 30 State: TTaskState; 31 WaitReason: TWaitReason; 32 WakeUpTime: TDateTime; 22 33 Terminated: Boolean; 23 34 EntryPoint: TTaskEvent; 35 Messages: TObjectQueue; // TQueue<TIPMessage> 36 procedure WaitForMessage; 37 procedure Sleep(Duration: TDateTime); 24 38 constructor Create; virtual; 39 destructor Destroy; override; 25 40 end; 26 41 … … 33 48 Tasks: TNamedObjectList; // TList<TTask> 34 49 Running: Boolean; 50 function GetCurrentTask: TTask; virtual; 35 51 procedure Start; virtual; 36 52 procedure Stop; virtual; 37 53 function AddTask(Name: string; EntryPoint: TTaskEvent): TTask; virtual; 54 procedure SwitchNext; virtual; 38 55 constructor Create; virtual; 39 56 destructor Destroy; override; … … 56 73 constructor Create; virtual; 57 74 procedure Service(Index: Integer; DataIn, DataOut: TMemory); virtual; 75 end; 76 77 TTimer = class 78 Period: TDateTime; 79 end; 80 81 TScreen = class 82 Size: TPoint; 83 DPI: Integer; 58 84 end; 59 85 … … 67 93 FileSystemClass: TFileSystemClass; 68 94 Devices: TNamedObjectList; // TList<TDevice> 95 Screens: TObjectList; // TList<TScreen> 69 96 procedure AppExecute(AFile: TFile); 70 97 procedure Init; … … 106 133 { TTask } 107 134 135 procedure TTask.WaitForMessage; 136 begin 137 WaitReason := wrMessage; 138 State := tsWaiting; 139 Scheduler.SwitchNext; 140 end; 141 142 procedure TTask.Sleep(Duration: TDateTime); 143 begin 144 WakeUpTime := Now + Duration; 145 State := tsWaiting; 146 WaitReason := wrSleep; 147 Scheduler.SwitchNext; 148 end; 149 108 150 constructor TTask.Create; 109 151 begin 110 152 Messages := TObjectQueue.Create; 153 end; 154 155 destructor TTask.Destroy; 156 begin 157 Messages.Free; 158 inherited Destroy; 111 159 end; 112 160 113 161 { TScheduler } 114 162 163 function TScheduler.GetCurrentTask: TTask; 164 begin 165 Result := nil; 166 end; 167 115 168 procedure TScheduler.Start; 116 169 begin … … 128 181 begin 129 182 NewTask := TaskClass.Create; 183 NewTask.Scheduler := Self; 130 184 NewTask.Name := Name; 131 185 NewTask.EntryPoint := EntryPoint; 132 186 Tasks.Add(NewTask); 133 187 Result := NewTask; 188 end; 189 190 procedure TScheduler.SwitchNext; 191 begin 192 134 193 end; 135 194 … … 201 260 Apps := TNamedObjectList.Create; 202 261 Scheduler := TScheduler.Create; 262 Screens := TObjectList.Create; 203 263 end; 204 264 205 265 destructor TKernel.Destroy; 206 266 begin 267 Screens.Free; 207 268 Scheduler.Free; 208 269 Apps.Free;
Note:
See TracChangeset
for help on using the changeset viewer.