Changeset 151 for MicroThreading/UMicroThreading.pas
- Timestamp:
- Jan 27, 2011, 8:05:33 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/UMicroThreading.pas
r150 r151 52 52 FManager: TMicroThreadManager; 53 53 FId: Integer; 54 procedure CallExecute; 54 55 function GetStackUsed: Integer; 56 procedure SetScheduler(const AValue: TMicroThreadScheduler); 55 57 public 56 58 Name: string; … … 77 79 write FFreeOnTerminate; 78 80 property Terminated: Boolean read FTerminated; 79 property Scheduler: TMicroThreadScheduler read FScheduler; 81 property Scheduler: TMicroThreadScheduler read FScheduler 82 write SetScheduler; 80 83 property Manager: TMicroThreadManager read FManager; 81 84 property StackUsed: Integer read GetStackUsed; … … 112 115 FExecutedCount: Integer; 113 116 FTerminated: Boolean; 114 FTempPointer: Pointer;115 117 FCurrentMicroThread: TMicroThread; 116 118 FScheduler: TMicroThreadScheduler; … … 177 179 implementation 178 180 179 var180 StaticManagers: TObjectList; // TList<TMicroThreadManager>;181 StaticManager: TMicroThreadManager;182 StaticMicroThread: TMicroThread;181 //var 182 // StaticManagers: TObjectList; // TList<TMicroThreadManager>; 183 // StaticManager: TMicroThreadManager; 184 // StaticMicroThread: TMicroThread; 183 185 184 186 function GetMicroThreadId: Integer; … … 231 233 if FCurrentMicroThread.FState = tsRunning then 232 234 FCurrentMicroThread.FState := tsWaiting; 233 StaticMicroThread := FCurrentMicroThread;234 235 asm 235 236 // Store microthread stack 236 mov eax, StaticMicroThread 237 mov ecx, Self 238 mov eax, [ecx].TMicroThreadManager.FCurrentMicroThread 237 239 mov edx, esp 238 240 mov [eax].TMicroThread.FStackPointer, edx 239 241 mov edx, ebp 240 242 mov [eax].TMicroThread.FBasePointer, edx 241 end; 242 StaticManager := FCurrentMicroThread.FManager; 243 asm 243 244 244 // Restore FScheduler stack 245 mov eax, StaticManager // Self is invalid before BP restore 246 mov edx, [eax].TMicroThreadManager.FStackPointer 245 mov edx, [ecx].TMicroThreadManager.FStackPointer 247 246 mov esp, edx 248 mov edx, [e ax].TMicroThreadManager.FBasePointer247 mov edx, [ecx].TMicroThreadManager.FBasePointer 249 248 mov ebp, edx 250 249 end; … … 270 269 FCurrentMicroThread.FState := tsRunning; 271 270 FCurrentMicroThread.FExecutionStartTime := CurrentTime; 272 StaticMicroThread := FCurrentMicroThread;273 271 asm 274 272 // Restore microthread stack 275 mov eax, StaticMicroThread 273 mov ecx, Self 274 mov eax, [ecx].TMicroThreadManager.FCurrentMicroThread 276 275 mov edx, [eax].TMicroThread.FStackPointer 277 276 mov ecx, esp … … 281 280 mov edx, [eax].TMicroThread.FBasePointer 282 281 mov ebp, edx 283 end; 284 StaticMicroThread.Execute; 285 asm 282 // We want to call virtual method Execute 283 // but virtual methods can be called only statically 284 // Then static method CallExecute is calling virtual method Execute 285 call TMicroThread.CallExecute 286 // end; 287 // StaticMicroThread.Execute; 288 // asm 286 289 pop edx 287 290 pop ebp … … 320 323 FCurrentMicroThread.FState := tsRunning; 321 324 FCurrentMicroThread.FExecutionStartTime := CurrentTime; 322 FTempPointer := FCurrentMicroThread.FStackPointer;323 325 asm 324 326 // Restore microthread stack 325 mov eax, Self 326 mov edx, [eax].TMicroThreadManager.FTempPointer 327 mov ecx, Self 328 mov eax, [ecx].TMicroThreadManager.FCurrentMicroThread 329 mov edx, [eax].TMicroThread.FStackPointer 327 330 mov esp, edx 328 end; 329 FTempPointer := FCurrentMicroThread.FBasePointer; 330 asm 331 mov eax, Self 332 mov edx, [eax].TMicroThreadManager.FTempPointer 331 mov edx, [eax].TMicroThread.FBasePointer 333 332 mov ebp, edx 334 333 end; … … 391 390 { TMicroThread } 392 391 392 procedure TMicroThread.CallExecute; 393 begin 394 Execute; 395 end; 396 393 397 function TMicroThread.GetStackUsed: Integer; 394 398 begin 395 399 Result := FStack + FStackSize - FStackPointer; 400 end; 401 402 procedure TMicroThread.SetScheduler(const AValue: TMicroThreadScheduler); 403 begin 404 FScheduler := AValue; 396 405 end; 397 406 … … 435 444 FStack := GetMem(FStackSize); 436 445 FBasePointer := FStack + FStackSize; 437 FStackPointer := FBasePointer - 20;446 FStackPointer := FBasePointer - SizeOf(Pointer); 438 447 FExecutionTime := 0; 439 448 FTerminated := False; … … 676 685 initialization 677 686 678 StaticManagers := TObjectList.Create;687 //StaticManagers := TObjectList.Create; 679 688 MainScheduler := TMicroThreadScheduler.Create; 680 689 … … 682 691 683 692 MainScheduler.Free; 684 StaticManagers.Free;693 //StaticManagers.Free; 685 694 686 695 end.
Note:
See TracChangeset
for help on using the changeset viewer.