Ignore:
Timestamp:
Feb 10, 2011, 4:10:59 PM (14 years ago)
Author:
george
Message:
  • Added: Context menu in microthreads list to show microthread call stack.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/UMicroThreading.pas

    r166 r168  
    141141    property Manager: TMicroThreadManager read FManager write SetManager;
    142142    property StackUsed: Integer read GetStackUsed;
     143    property BasePointer: Pointer read FBasePointer;
    143144  end;
    144145
     
    391392    Dec(FCounter);
    392393    if FMicroThreads.Count > 0 then begin
    393       // Release one waiting micro thread and lower counter
     394      // Release one waiting micro thread
    394395      TMicroThread(FMicroThreads[0]).FState := tsWaiting;
    395396      FMicroThreads.Delete(0);
     
    435436  Form := TMicroThreadListForm.Create(Self);
    436437end;
    437 
    438 
    439438
    440439{ TMicroThreadMethod }
     
    797796begin
    798797  try
     798    FScheduler.FMicroThreadsLock.Acquire;
    799799    CriticalSection.Lock.Acquire;
    800800    Inc(CriticalSection.FCounter);
     
    805805      try
    806806        CriticalSection.Lock.Release;
     807        FScheduler.FMicroThreadsLock.Release;
    807808        Yield;
    808809      finally
     810        FScheduler.FMicroThreadsLock.Acquire;
    809811        CriticalSection.Lock.Acquire;
    810812      end;
     
    812814  finally
    813815    CriticalSection.Lock.Release;
     816    FScheduler.FMicroThreadsLock.Release;
    814817  end;
    815818end;
     
    845848  const StackSize: SizeUInt = DefaultStackSize);
    846849begin
     850  // Setup stack
    847851  FStackSize := StackSize;
    848852  FStack := GetMem(FStackSize);
    849   FBasePointer := FStack + FStackSize;
     853  FBasePointer := FStack + FStackSize - SizeOf(Pointer);
    850854  FStackPointer := FBasePointer - SizeOf(Pointer);
     855  FillChar(FStackPointer^, 2 * SizeOf(Pointer), 0);
     856
    851857  FExecutionTime := 0;
    852858  FState := tsWaiting;
     
    886892
    887893procedure TMicroThread.Suspend;
     894var
     895  MT: TMicroThread;
    888896begin
    889897  FStatePending := tsSuspended;
    890   //Yield;
     898  MT := GetCurrentMicroThread;
     899  if Assigned(MT) then Yield;
    891900end;
    892901
     
    918927begin
    919928  try
    920     NewMicroThread := TMicroThreadSimple.Create(False);
     929    NewMicroThread := TMicroThreadSimple.Create(True);
    921930    NewMicroThread.Method := Method;
    922931    NewMicroThread.FScheduler := Self;
    923932    NewMicroThread.FreeOnTerminate := not WaitForFinish;
     933    NewMicroThread.Start;
    924934    if WaitForFinish then begin
    925935      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;
    934949          end;
    935         finally
    936           FMicroThreadsLock.Acquire;
    937950        end;
     951      finally
     952        FMicroThreadsLock.Release;
    938953      end;
    939954    end;
Note: See TracChangeset for help on using the changeset viewer.