Ignore:
Timestamp:
Jan 27, 2011, 10:56:06 AM (14 years ago)
Author:
george
Message:
  • Added: Synchronize method.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • MicroThreading/UMicroThreading.pas

    r152 r153  
    6969    procedure Resume;
    7070    procedure Suspend;
     71    procedure Synchronize(AMethod: TThreadMethod);
    7172
    7273    constructor Create(CreateSuspended: Boolean;
     
    118119    FCurrentMicroThread: TMicroThread;
    119120    FScheduler: TMicroThreadScheduler;
     121    FThread: TMicroThreadThread;
    120122    function Execute(Count: Integer): Integer;
    121123  public
    122124    Id: Integer;
    123125    procedure Yield;
     126    procedure Synchronize(AMethod: TThreadMethod);
    124127    constructor Create;
    125128    destructor Destroy; override;
     
    332335end;
    333336
     337procedure TMicroThreadManager.Synchronize(AMethod: TThreadMethod);
     338begin
     339  if Assigned(FThread) then
     340    FThread.Synchronize(FThread, AMethod);
     341end;
     342
    334343constructor TMicroThreadManager.Create;
    335344begin
    336345  FCurrentMicroThread := nil;
     346  FThread := nil;
    337347end;
    338348
     
    487497  FSuspended := True;
    488498  //Yield;
     499end;
     500
     501procedure TMicroThread.Synchronize(AMethod: TThreadMethod);
     502begin
     503  FManager.Synchronize(AMethod);
    489504end;
    490505
     
    538553  FMainThreadManager.Free;
    539554  FThreadPool.Free;
     555  FThreadPoolLock.Free;
    540556  FMicroThreads.Free;
    541557  FMicroThreadsLock.Free;
     
    548564  UpdateThreadPoolSize;
    549565  FState := ssRunning;
     566  if FUseMainThread then
     567    FMainThreadStarter.Enabled := True;
    550568end;
    551569
     
    599617        NewThread := TMicroThreadThread.Create(True);
    600618        NewThread.Manager.FScheduler := Self;
    601         NewThread.Manager.Id := FThreadPool.Count;
     619        NewThread.Manager.Id := FThreadPool.Count + 1;
     620        NewThread.Manager.FThread := NewThread;
    602621        NewThread.OnTerminate := PoolThreadTerminated;
    603622        ThreadPool.Add(NewThread);
Note: See TracChangeset for help on using the changeset viewer.