mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-11-05 08:01:53 +01:00
* Added TLazThreadedQueue.PopItemTimeout to be able to specify different timeout then the default
git-svn-id: trunk@51236 -
This commit is contained in:
parent
cf0f53eb93
commit
c65c09f800
@ -48,6 +48,7 @@ type
|
|||||||
procedure Grow(ADelta: integer);
|
procedure Grow(ADelta: integer);
|
||||||
function PushItem(const AItem: T): TWaitResult;
|
function PushItem(const AItem: T): TWaitResult;
|
||||||
function PopItem(out AItem: T): TWaitResult;
|
function PopItem(out AItem: T): TWaitResult;
|
||||||
|
function PopItemTimeout(out AItem: T; Timeout: cardinal): TWaitResult;
|
||||||
procedure DoShutDown;
|
procedure DoShutDown;
|
||||||
property QueueSize: integer read FQueueSize;
|
property QueueSize: integer read FQueueSize;
|
||||||
property TotalItemsPopped: QWord read FTotalItemsPopped;
|
property TotalItemsPopped: QWord read FTotalItemsPopped;
|
||||||
@ -243,10 +244,15 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
function TLazThreadedQueue.PopItem(out AItem: T): TWaitResult;
|
function TLazThreadedQueue.PopItem(out AItem: T): TWaitResult;
|
||||||
|
begin
|
||||||
|
result := PopItemTimeout(AItem, FPopTimeout);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TLazThreadedQueue.PopItemTimeout(out AItem: T; Timeout: cardinal): TWaitResult;
|
||||||
var
|
var
|
||||||
tc, ltc: int64;
|
tc, ltc: int64;
|
||||||
begin
|
begin
|
||||||
if (FPopTimeout<>INFINITE) and (FPopTimeout<>0) then
|
if (Timeout<>INFINITE) and (Timeout<>0) then
|
||||||
begin
|
begin
|
||||||
tc := GetTickCount64;
|
tc := GetTickCount64;
|
||||||
ltc := 0;
|
ltc := 0;
|
||||||
@ -255,19 +261,19 @@ begin
|
|||||||
result := wrSignaled
|
result := wrSignaled
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
repeat
|
if Timeout=0 then
|
||||||
if FPopTimeout=0 then
|
|
||||||
begin
|
begin
|
||||||
result := wrTimeout;
|
result := wrTimeout;
|
||||||
Exit;
|
Exit;
|
||||||
end
|
end;
|
||||||
else if FPopTimeout=INFINITE then
|
repeat
|
||||||
|
if Timeout=INFINITE then
|
||||||
RTLeventWaitFor(FHasItemEvent)
|
RTLeventWaitFor(FHasItemEvent)
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
RTLeventWaitFor(FHasItemEvent, FPopTimeout - ltc);
|
RTLeventWaitFor(FHasItemEvent, Timeout - ltc);
|
||||||
ltc := GetTickCount64-tc;
|
ltc := GetTickCount64-tc;
|
||||||
if ltc > FPopTimeout then
|
if ltc > Timeout then
|
||||||
begin
|
begin
|
||||||
result := wrTimeout;
|
result := wrTimeout;
|
||||||
Exit;
|
Exit;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user