Changeset 168 for MicroThreading/UMicroThreading.pas
- Timestamp:
- Feb 10, 2011, 4:10:59 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
MicroThreading/UMicroThreading.pas
r166 r168 141 141 property Manager: TMicroThreadManager read FManager write SetManager; 142 142 property StackUsed: Integer read GetStackUsed; 143 property BasePointer: Pointer read FBasePointer; 143 144 end; 144 145 … … 391 392 Dec(FCounter); 392 393 if FMicroThreads.Count > 0 then begin 393 // Release one waiting micro thread and lower counter394 // Release one waiting micro thread 394 395 TMicroThread(FMicroThreads[0]).FState := tsWaiting; 395 396 FMicroThreads.Delete(0); … … 435 436 Form := TMicroThreadListForm.Create(Self); 436 437 end; 437 438 439 438 440 439 { TMicroThreadMethod } … … 797 796 begin 798 797 try 798 FScheduler.FMicroThreadsLock.Acquire; 799 799 CriticalSection.Lock.Acquire; 800 800 Inc(CriticalSection.FCounter); … … 805 805 try 806 806 CriticalSection.Lock.Release; 807 FScheduler.FMicroThreadsLock.Release; 807 808 Yield; 808 809 finally 810 FScheduler.FMicroThreadsLock.Acquire; 809 811 CriticalSection.Lock.Acquire; 810 812 end; … … 812 814 finally 813 815 CriticalSection.Lock.Release; 816 FScheduler.FMicroThreadsLock.Release; 814 817 end; 815 818 end; … … 845 848 const StackSize: SizeUInt = DefaultStackSize); 846 849 begin 850 // Setup stack 847 851 FStackSize := StackSize; 848 852 FStack := GetMem(FStackSize); 849 FBasePointer := FStack + FStackSize ;853 FBasePointer := FStack + FStackSize - SizeOf(Pointer); 850 854 FStackPointer := FBasePointer - SizeOf(Pointer); 855 FillChar(FStackPointer^, 2 * SizeOf(Pointer), 0); 856 851 857 FExecutionTime := 0; 852 858 FState := tsWaiting; … … 886 892 887 893 procedure TMicroThread.Suspend; 894 var 895 MT: TMicroThread; 888 896 begin 889 897 FStatePending := tsSuspended; 890 //Yield; 898 MT := GetCurrentMicroThread; 899 if Assigned(MT) then Yield; 891 900 end; 892 901 … … 918 927 begin 919 928 try 920 NewMicroThread := TMicroThreadSimple.Create( False);929 NewMicroThread := TMicroThreadSimple.Create(True); 921 930 NewMicroThread.Method := Method; 922 931 NewMicroThread.FScheduler := Self; 923 932 NewMicroThread.FreeOnTerminate := not WaitForFinish; 933 NewMicroThread.Start; 924 934 if WaitForFinish then begin 925 935 CurrentMT := GetCurrentMicroThread; 926 while not ((NewMicroThread.FState = tsBlocked) and 927 (NewMicroThread.FBlockState = tbsTerminated)) do begin 928 try 929 FMicroThreadsLock.Release; 930 if Assigned(CurrentMT) then CurrentMT.MTSleep(1 * OneMillisecond) 931 else begin 932 Sleep(1); 933 Application.ProcessMessages; 936 try 937 FMicroThreadsLock.Acquire; 938 while not ((NewMicroThread.FState = tsBlocked) and 939 (NewMicroThread.FBlockState = tbsTerminated)) do begin 940 try 941 FMicroThreadsLock.Release; 942 if Assigned(CurrentMT) then CurrentMT.MTSleep(1 * OneMillisecond) 943 else begin 944 Sleep(1); 945 Application.ProcessMessages; 946 end; 947 finally 948 FMicroThreadsLock.Acquire; 934 949 end; 935 finally936 FMicroThreadsLock.Acquire;937 950 end; 951 finally 952 FMicroThreadsLock.Release; 938 953 end; 939 954 end;
Note:
See TracChangeset
for help on using the changeset viewer.