Changeset 164 for MicroThreading/UMicroThreading.pas
- Timestamp:
- Feb 8, 2011, 11:05:30 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/UMicroThreading.pas
r162 r164 24 24 25 25 const 26 DefaultStackSize = $ 4000;26 DefaultStackSize = $8000; 27 27 28 28 resourcestring … … 210 210 FMainThreadStarter: TTimer; 211 211 FEvents: TObjectList; 212 FMainThreadOutsideStart: TDateTime; 213 FMainThreadOutsideDuration: TDateTime; 212 214 function GetMicroThreadCount: Integer; 213 215 function GetThreadPoolCount: Integer; … … 241 243 property Active: Boolean read FActive write SetActive; 242 244 property UseMainThread: Boolean read FUseMainThread write SetUseMainThread; 245 property MainThreadOutsideDuration: TDateTime read FMainThreadOutsideDuration; 243 246 end; 244 247 … … 339 342 MT := GetCurrentMicroThread; 340 343 if Assigned(MT) then Result := MT.WaitForEvent(Event, Duration) 341 else raise Exception.Create(SNotInThread); 344 else begin 345 while not Event.Signaled do begin 346 Sleep(1); 347 Application.ProcessMessages; 348 end; 349 //raise Exception.Create(SNotInThread); 342 350 // else Result := Event.WaitFor(Trunc(Duration / OneMillisecond)); 351 end; 343 352 end; 344 353 … … 487 496 function TMicroThreadManager.Execute(Count: Integer): Integer; 488 497 begin 489 FLoopStart := NowPrecise;498 //FLoopStart := NowPrecise; 490 499 FStack := StackBottom; 491 500 FStackSize := StackBottom + StackLength; … … 494 503 Yield; 495 504 Result := FExecutedCount; 496 FLoopDuration := NowPrecise - FLoopStart;505 //FLoopDuration := NowPrecise - FLoopStart; 497 506 end; 498 507 … … 615 624 begin 616 625 if Assigned(FThread) then 617 FThread.Synchronize(FThread, AMethod); 626 FThread.Synchronize(FThread, AMethod) 627 else AMethod; 618 628 end; 619 629 … … 744 754 procedure TMicroThread.WaitFor; 745 755 begin 746 if GetMicroThreadId <> -1 then 747 while not ((FState = tsBlocked) and (FBlockState = tbsTerminated)) do begin 748 MTSleep(1); 756 if GetMicroThreadId <> -1 then begin 757 // Called from another microthread 758 while not ((FState = tsBlocked) and (FBlockState = tbsTerminated)) do begin 759 MTSleep(1); 760 end; 761 end else begin 762 // Called directly from main thread 763 while not ((FState = tsBlocked) and (FBlockState = tbsTerminated)) do begin 764 Sleep(1); 765 Application.ProcessMessages; 766 end; 749 767 end; 750 768 end; … … 762 780 try 763 781 Event.FMicroThreadsLock.Acquire; 782 if Event.Signaled then begin 783 Result := wrSignaled; 784 Exit; 785 end; 764 786 Event.FMicroThreads.Add(Self); 765 787 FBlockTime := NowPrecise + Duration; … … 890 912 FMainThreadManager.FScheduler := Self; 891 913 UseMainThread := False; 892 BurstCount := 100;914 BurstCount := 50; 893 915 end; 894 916 … … 984 1006 begin 985 1007 // try 986 Duration := 100 * OneMillisecond; 987 StartTime := NowPrecise; 1008 FMainThreadOutsideDuration := NowPrecise - FMainThreadOutsideStart; 1009 BurstCount := 1; 1010 Duration := 50 * OneMillisecond; 1011 StartTime := Now; 988 1012 Executed := -1; 989 while (Executed <> 0) and ((Now Precise- StartTime) < Duration) do begin1013 while (Executed <> 0) and ((Now - StartTime) < Duration) do begin 990 1014 Executed := FMainThreadManager.Execute(BurstCount); 991 1015 end; … … 999 1023 // raise; 1000 1024 // end; 1025 FMainThreadOutsideStart := NowPrecise; 1001 1026 end; 1002 1027
Note:
See TracChangeset
for help on using the changeset viewer.