Changeset 158 for MicroThreading/UMicroThreading.pas
- Timestamp:
- Jan 28, 2011, 9:10:16 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/UMicroThreading.pas
r157 r158 178 178 FUseMainThread: Boolean; 179 179 FMainThreadStarter: TTimer; 180 FEvents: TObjectList; 180 181 function GetMicroThreadCount: Integer; 181 182 function GetThreadPoolCount: Integer; … … 322 323 I: Integer; 323 324 begin 324 for I := 0 to FMicroThreads.Count - 1 do 325 TMicroThread(FMicroThreads[I]).FStatePending := tsWaiting; 326 if not FAutoReset then FSignaled := True; 325 try 326 MainScheduler.FMicroThreadsLock.Acquire; 327 for I := 0 to FMicroThreads.Count - 1 do 328 with TMicroThread(FMicroThreads[I]) do begin 329 if (FState = tsBlocked) and (FBlockState = tbsWaitFor) then 330 FState := tsWaiting; 331 end; 332 if not FAutoReset then FSignaled := True; 333 finally 334 MainScheduler.FMicroThreadsLock.Release; 335 end; 327 336 end; 328 337 … … 342 351 constructor TMicroThreadEvent.Create; 343 352 begin 353 FAutoReset := True; 344 354 FMicroThreads := TObjectList.Create; 345 355 FMicroThreads.OwnsObjects := False; 346 356 FMicroThreadsLock := TCriticalSection.Create; 357 MainScheduler.FEvents.Add(Self); 347 358 end; 348 359 349 360 destructor TMicroThreadEvent.Destroy; 350 361 begin 362 MainScheduler.FEvents.Delete(MainScheduler.FEvents.IndexOf(Self)); 351 363 FMicroThreadsLock.Free; 352 364 FMicroThreads.Free; … … 399 411 end; 400 412 FCurrentMicroThread.CheckStack; 401 if FCurrentMicroThread = nil then402 raise Exception.Create('x');403 413 FScheduler.ReleaseMicroThread(FCurrentMicroThread); 404 414 end; … … 588 598 if not Assigned(FManager) then 589 599 raise Exception.Create('Manager reference lost'); 590 FStatePending := tsWaiting; 600 if FStatePending = tsNone then 601 FStatePending := tsWaiting; 591 602 FManager.Yield; 592 603 end; … … 613 624 Event.FMicroThreadsLock.Acquire; 614 625 Event.FMicroThreads.Add(Self); 626 FBlockTime := NowPrecise + Duration; 627 FBlockState := tbsWaitFor; 628 FStatePending := tsBlocked; 615 629 finally 616 630 Event.FMicroThreadsLock.Release; 617 631 end; 618 FBlockTime := NowPrecise + Duration;619 FBlockState := tbsWaitFor;620 FStatePending := tsBlocked;621 632 Yield; 622 633 try … … 642 653 end; 643 654 FFreeOnTerminate := True; 655 MainScheduler.Add(Self); 644 656 end; 645 657 … … 718 730 constructor TMicroThreadScheduler.Create; 719 731 begin 732 FEvents := TObjectList.Create; 720 733 FMainThreadStarter := TTimer.Create(nil); 721 734 FMainThreadStarter.Enabled := False; … … 742 755 FMicroThreads.Free; 743 756 FMicroThreadsLock.Free; 757 FEvents.Free; 744 758 inherited Destroy; 745 759 end; … … 878 892 begin 879 893 if not Assigned(MicroThread) then 880 raise Exception.Create('Can''t re alease nil thread.');894 raise Exception.Create('Can''t release nil thread.'); 881 895 try 882 896 FMicroThreadsLock.Acquire;
Note:
See TracChangeset
for help on using the changeset viewer.