From 0e3e994612707471a8d3f3cafe364c4e5ba9fa8e Mon Sep 17 00:00:00 2001 From: mgaertner Date: Thu, 6 Jan 2011 12:01:14 +0000 Subject: [PATCH] mtprocs: fixed moving group from need thread list after increasing LastRunningIndex, added CurrentThread variable git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1426 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- components/multithreadprocs/mtprocs.pas | 26 +++++++++++++------ components/multithreadprocs/mtputils.pas | 2 +- .../multithreadprocs/multithreadprocslaz.lpk | 10 ++++--- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/components/multithreadprocs/mtprocs.pas b/components/multithreadprocs/mtprocs.pas index 986fd2d7d..ec1a24102 100644 --- a/components/multithreadprocs/mtprocs.pas +++ b/components/multithreadprocs/mtprocs.pas @@ -127,6 +127,7 @@ type procedure AddToList(var First: TProcThreadGroup; ListType: TMTPGroupState); inline; procedure RemoveFromList(var First: TProcThreadGroup); inline; function NeedMoreThreads: boolean; inline; + procedure IncreaseLastRunningIndex(Item: TMultiThreadProcItem); procedure AddThread(AThread: TProcThread); procedure RemoveThread(AThread: TProcThread); inline; procedure Run(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem); inline; @@ -203,6 +204,8 @@ type var ProcThreadPool: TProcThreadPool = nil; +threadvar + CurrentThread: TThread; // TProcThread sets this, you can set this for your own TThreads descendants implementation @@ -338,6 +341,7 @@ var ok: Boolean; E: Exception; begin + CurrentThread:=Self; aPool:=Item.Group.Pool; ok:=false; try @@ -353,8 +357,7 @@ begin // find next work if Group.LastRunningIndexmtpgsException); end; +procedure TProcThreadGroup.IncreaseLastRunningIndex(Item: TMultiThreadProcItem); +begin + inc(FLastRunningIndex); + Item.FIndex:=FLastRunningIndex; + if NeedMoreThreads then exit; + if FState=mtpgsNeedThreads then begin + RemoveFromList(Pool.FFirstGroupNeedThreads); + AddToList(Pool.FFirstGroupFinishing,mtpgsFinishing); + end; +end; + procedure TProcThreadGroup.AddThread(AThread: TProcThread); begin AThread.Item.FGroup:=Self; AThread.AddToList(FFirstThread,mtptlGroup); inc(FThreadCount); - inc(FLastRunningIndex); - AThread.Item.FIndex:=FLastRunningIndex; - if not NeedMoreThreads then begin - RemoveFromList(Pool.FFirstGroupNeedThreads); - AddToList(Pool.FFirstGroupFinishing,mtpgsFinishing); - end; + IncreaseLastRunningIndex(AThread.Item); end; procedure TProcThreadGroup.RemoveThread(AThread: TProcThread); @@ -856,6 +865,7 @@ end; initialization ProcThreadPool:=TProcThreadPool.Create; + CurrentThread:=nil; finalization ProcThreadPool.Free; diff --git a/components/multithreadprocs/mtputils.pas b/components/multithreadprocs/mtputils.pas index dbe42a5f3..1a89a8b2f 100644 --- a/components/multithreadprocs/mtputils.pas +++ b/components/multithreadprocs/mtputils.pas @@ -35,7 +35,7 @@ type fBlockSize: PtrInt; fBlockCntPowOf2Offset: PtrInt; FMergeBuffer: PPointer; - procedure MTPSort(Index: PtrInt; Data: Pointer; Item: TMultiThreadProcItem); + procedure MTPSort(Index: PtrInt; {%H-}Data: Pointer; Item: TMultiThreadProcItem); public List: PPointer; Count: PtrInt; diff --git a/components/multithreadprocs/multithreadprocslaz.lpk b/components/multithreadprocs/multithreadprocslaz.lpk index f99d41edb..69fd162e1 100644 --- a/components/multithreadprocs/multithreadprocslaz.lpk +++ b/components/multithreadprocs/multithreadprocslaz.lpk @@ -2,8 +2,9 @@ + - + @@ -11,7 +12,9 @@ - + + + @@ -35,11 +38,12 @@ - + +