mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-05 10:46:19 +02:00
* use sem_timedwait for BasicEventWaitFor if available (linux now)
git-svn-id: trunk@8835 -
This commit is contained in:
parent
83bab3b071
commit
5f3e2b10e8
@ -36,6 +36,10 @@
|
|||||||
{$endif}
|
{$endif}
|
||||||
{$endif}
|
{$endif}
|
||||||
|
|
||||||
|
{$ifdef linux}
|
||||||
|
{$define has_sem_timedwait}
|
||||||
|
{$endif}
|
||||||
|
|
||||||
unit cthreads;
|
unit cthreads;
|
||||||
interface
|
interface
|
||||||
{$S-}
|
{$S-}
|
||||||
@ -444,6 +448,22 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{$if defined(has_sem_timedwait)}
|
||||||
|
|
||||||
|
function cSemaphoreTimedWait(const FSem: Pointer; const Timeout: ttimespec): cint;
|
||||||
|
var
|
||||||
|
res: cint;
|
||||||
|
err: cint;
|
||||||
|
begin
|
||||||
|
repeat
|
||||||
|
res:=sem_timedwait(PSemaphore(FSem), @Timeout);
|
||||||
|
if res=0 then exit(0);
|
||||||
|
err:=fpgetCerrno;
|
||||||
|
until err<>ESysEINTR;
|
||||||
|
result:=err;
|
||||||
|
end;
|
||||||
|
|
||||||
|
{$endif}
|
||||||
|
|
||||||
procedure cSemaphorePost(const FSem: Pointer);
|
procedure cSemaphorePost(const FSem: Pointer);
|
||||||
{$if defined(has_sem_init) or defined(has_sem_open)}
|
{$if defined(has_sem_init) or defined(has_sem_open)}
|
||||||
@ -783,7 +803,23 @@ begin
|
|||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
timespec.tv_sec:=0;
|
{$ifdef has_sem_timedwait}
|
||||||
|
fpgettimeofday(@timespec,nil);
|
||||||
|
inc(timespec.tv_nsec, (timeout mod 1000) * 1000000);
|
||||||
|
inc(timespec.tv_sec, timeout div 1000);
|
||||||
|
if timespec.tv_nsec > 1000000000 then
|
||||||
|
begin
|
||||||
|
dec(timespec.tv_nsec, 1000000000);
|
||||||
|
inc(timespec.tv_sec);
|
||||||
|
end;
|
||||||
|
nanores := cSemaphoreTimedWait(plocaleventstate(state)^.FSem, timespec);
|
||||||
|
if nanores = 0 then
|
||||||
|
result := wrSignaled
|
||||||
|
else if nanores = ESysETIMEDOUT then
|
||||||
|
result := wrTimeout
|
||||||
|
else
|
||||||
|
result := wrError;
|
||||||
|
{$else}
|
||||||
{ 500 miliseconds or less -> wait once for this duration }
|
{ 500 miliseconds or less -> wait once for this duration }
|
||||||
if (timeout <= 500) then
|
if (timeout <= 500) then
|
||||||
loopcnt:=1
|
loopcnt:=1
|
||||||
@ -853,6 +889,7 @@ begin
|
|||||||
if (result<>wrTimeOut) then
|
if (result<>wrTimeOut) then
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if (result=wrSignaled) then
|
if (result=wrSignaled) then
|
||||||
|
Loading…
Reference in New Issue
Block a user