From c65c09f8001e720dfad39eb66370f9dcb900cce7 Mon Sep 17 00:00:00 2001 From: joost Date: Sun, 10 Jan 2016 15:45:53 +0000 Subject: [PATCH] * Added TLazThreadedQueue.PopItemTimeout to be able to specify different timeout then the default git-svn-id: trunk@51236 - --- components/lazutils/lazcollections.pas | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/components/lazutils/lazcollections.pas b/components/lazutils/lazcollections.pas index 52f49904e2..089fa5586b 100644 --- a/components/lazutils/lazcollections.pas +++ b/components/lazutils/lazcollections.pas @@ -48,6 +48,7 @@ type procedure Grow(ADelta: integer); function PushItem(const AItem: T): TWaitResult; function PopItem(out AItem: T): TWaitResult; + function PopItemTimeout(out AItem: T; Timeout: cardinal): TWaitResult; procedure DoShutDown; property QueueSize: integer read FQueueSize; property TotalItemsPopped: QWord read FTotalItemsPopped; @@ -243,10 +244,15 @@ begin end; function TLazThreadedQueue.PopItem(out AItem: T): TWaitResult; +begin + result := PopItemTimeout(AItem, FPopTimeout); +end; + +function TLazThreadedQueue.PopItemTimeout(out AItem: T; Timeout: cardinal): TWaitResult; var tc, ltc: int64; begin - if (FPopTimeout<>INFINITE) and (FPopTimeout<>0) then + if (Timeout<>INFINITE) and (Timeout<>0) then begin tc := GetTickCount64; ltc := 0; @@ -255,19 +261,19 @@ begin result := wrSignaled else begin - repeat - if FPopTimeout=0 then + if Timeout=0 then begin result := wrTimeout; Exit; - end - else if FPopTimeout=INFINITE then + end; + repeat + if Timeout=INFINITE then RTLeventWaitFor(FHasItemEvent) else begin - RTLeventWaitFor(FHasItemEvent, FPopTimeout - ltc); + RTLeventWaitFor(FHasItemEvent, Timeout - ltc); ltc := GetTickCount64-tc; - if ltc > FPopTimeout then + if ltc > Timeout then begin result := wrTimeout; Exit;