Changeset 3 for trunk/Platform/Base
- Timestamp:
- Nov 22, 2014, 11:50:49 PM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Platform/Base/UPlatformBase.pas
r2 r3 6 6 7 7 uses 8 Classes, SysUtils, UFileSystem ;8 Classes, SysUtils, UFileSystem, UKernel; 9 9 10 10 type 11 { TCustomThread } 12 13 TCustomThread = class(TThread) 14 Task: TTask; 15 procedure Execute; override; 16 end; 17 18 { TBaseTask } 19 20 TBaseTask = class(TTask) 21 Thread: TCustomThread; 22 constructor Create; override; 23 destructor Destroy; override; 24 end; 25 26 11 27 TBaseFileSystem = class(TFileSystem) 12 28 13 29 end; 14 30 31 { TBaseScheduler } 32 33 TBaseScheduler = class(TScheduler) 34 function AddTask(Name: string; EntryPoint: TEvent): TTask; override; 35 constructor Create; override; 36 procedure Start; override; 37 end; 38 15 39 implementation 40 41 { TBaseTask } 42 43 constructor TBaseTask.Create; 44 begin 45 inherited; 46 Thread := TCustomThread.Create(True); 47 Thread.Task := Self; 48 end; 49 50 destructor TBaseTask.Destroy; 51 begin 52 Thread.Free; 53 inherited Destroy; 54 end; 55 56 { TCustomThread } 57 58 procedure TCustomThread.Execute; 59 begin 60 Task.EntryPoint; 61 end; 62 63 { TBaseScheduler } 64 65 function TBaseScheduler.AddTask(Name: string; EntryPoint: TEvent): TTask; 66 var 67 Task: TBaseTask; 68 begin 69 Task := TBaseTask(inherited AddTask(Name, EntryPoint)); 70 if Running then Task.Thread.Start; 71 end; 72 73 constructor TBaseScheduler.Create; 74 begin 75 inherited Create; 76 TaskClass := TBaseTask; 77 end; 78 79 procedure TBaseScheduler.Start; 80 var 81 I: Integer; 82 begin 83 inherited Start; 84 for I := 0 to Tasks.Count - 1 do 85 TBaseTask(Tasks[I]).Thread.Start; 86 end; 16 87 17 88 end.
Note:
See TracChangeset
for help on using the changeset viewer.