Changeset 161 for MicroThreading/UMicroThreading.pas
- Timestamp:
- Feb 7, 2011, 7:04:23 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/UMicroThreading.pas
r160 r161 28 28 SNilThreadReference = 'Can''t release nil thread.'; 29 29 SManagerMicroThreadRunning = 'Manager already have running microthread'; 30 SManagerReferenceLost = 'Reference to manager lost'; 31 SCantDetermineThreadID = 'Can''t determine thread for id %d'; 32 SNotInThread = 'Not in thread'; 33 30 34 31 35 type … … 69 73 FStackSize: Integer; 70 74 FBasePointer: Pointer; 75 FExceptObjectStack: PExceptObject; 76 FExceptAddrStack: PExceptAddr; 71 77 FExecuted: Boolean; // At first go through Execute method, then switch context 72 78 FBlockState: TMicroThreadBlockState; … … 146 152 FStackPointer: Pointer; 147 153 FBasePointer: Pointer; 154 FExceptObjectStack: PExceptObject; 155 FExceptAddrStack: PExceptAddr; 148 156 FExecuteCount: Integer; 149 157 FExecutedCount: Integer; … … 302 310 Thread := TThreadEx.CurrentThread; 303 311 if Assigned(Thread) then TThread.Synchronize(Thread, Method) 304 else raise Exception.Create( 'Can''t determine thread for id ' + IntToStr(GetCurrentThreadId));312 else raise Exception.Create(Format(SCantDetermineThreadID, [GetCurrentThreadId])); 305 313 end else Method; 306 314 end; … … 312 320 MT := GetCurrentMicroThread; 313 321 if Assigned(MT) then Result := MT.WaitForEvent(Event, Duration) 314 else raise Exception.Create( 'Not in thread');322 else raise Exception.Create(SNotInThread); 315 323 // else Result := Event.WaitFor(Trunc(Duration / OneMillisecond)); 316 324 end; … … 428 436 FCurrentMicroThread.FExecutionTime := FCurrentMicroThread.FExecutionTime + 429 437 (FCurrentMicroThread.FExecutionEndTime - FCurrentMicroThread.FExecutionStartTime); 438 439 FCurrentMicroThread.FExceptObjectStack := GetExceptionObjectStack; 440 FCurrentMicroThread.FExceptAddrStack := GetExceptionAddrStack; 430 441 asm 431 442 // Store microthread stack … … 443 454 mov ebp, ebx 444 455 end; 456 SetExceptionObjectStack(FExceptObjectStack); 457 SetExceptionAddrStack(FExceptAddrStack); 445 458 FCurrentMicroThread.CheckStack; 446 459 FScheduler.ReleaseMicroThread(FCurrentMicroThread); … … 452 465 Inc(FExecutedCount); 453 466 FCurrentMicroThread.FExecutionStartTime := NowPrecise; 467 FExceptObjectStack := GetExceptionObjectStack; 468 FExceptAddrStack := GetExceptionAddrStack; 454 469 asm 455 470 // Store manager stack … … 463 478 // First time micro thread execution 464 479 FCurrentMicroThread.FExecuted := True; 480 SetExceptionObjectStack(FCurrentMicroThread.FExceptObjectStack); 481 SetExceptionAddrStack(FCurrentMicroThread.FExceptAddrStack); 465 482 asm 466 483 // Restore microthread stack … … 484 501 mov ebp, ebx 485 502 end; 503 SetExceptionObjectStack(FExceptObjectStack); 504 SetExceptionAddrStack(FExceptAddrStack); 486 505 FCurrentMicroThread.CheckStack; 487 506 FCurrentMicroThread.FExecutionEndTime := NowPrecise; 488 507 FCurrentMicroThread.FExecutionTime := FCurrentMicroThread.FExecutionTime + 489 508 (FCurrentMicroThread.FExecutionEndTime - FCurrentMicroThread.FExecutionStartTime); 490 509 FCurrentMicroThread.FStatePending := tsBlocked; 491 510 FCurrentMicroThread.FBlockState := tbsTerminated; … … 496 515 FMicroThreadsLock.Acquire; 497 516 FMicroThreads.Delete(FMicroThreads.IndexOf(FCurrentMicroThread)); 517 FCurrentMicroThread.Manager := nil; 498 518 finally 499 519 FMicroThreadsLock.Release; … … 509 529 // Regular selected microthread execution 510 530 FCurrentMicroThread.CheckStack; 531 SetExceptionObjectStack(FCurrentMicroThread.FExceptObjectStack); 532 SetExceptionAddrStack(FCurrentMicroThread.FExceptAddrStack); 511 533 asm 512 534 // Restore microthread stack … … 635 657 begin 636 658 if not Assigned(FManager) then 637 raise Exception.Create( 'Manager reference lost');659 raise Exception.Create(SManagerReferenceLost); 638 660 if FStatePending = tsNone then 639 661 FStatePending := tsWaiting; … … 879 901 Executed: Integer; 880 902 begin 881 Executed := FMainThreadManager.Execute(1); 882 if Executed = 0 then Sleep(1); 883 // If not terminated then queue next tick else terminate 884 if (FState = ssRunning) and FUseMainThread then 885 Application.QueueAsyncCall(MainThreadTick, 0) 886 else FMainThreadTerminated := True; 903 // try 904 Executed := FMainThreadManager.Execute(1); 905 if Executed = 0 then Sleep(1); 906 // If not terminated then queue next tick else terminate 907 if (FState = ssRunning) and FUseMainThread then 908 Application.QueueAsyncCall(MainThreadTick, 0) 909 else FMainThreadTerminated := True; 910 // except 911 // FMainThreadTerminated := True; 912 // raise; 913 // end; 887 914 end; 888 915
Note:
See TracChangeset
for help on using the changeset viewer.