Issue about dwsXPlatformTimer
Opened this issue · 1 comments
achinastone commented
achinastone commented
`
function TdwsXTimerQueue.Add(const AInterval: Cardinal; AEvent : TTimerEvent; const AOnTimer: TWaitOrTimerCallback): THandle;
var
Handle : THandle;
Timer : TdwsXTimer;
Event : epoll_event;
begin
Result := INVALID_HANDLE_VALUE;
Handle := timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
if Handle <> THandle(-1) then
begin
Timer := TdwsXTimer.Create;
Timer.Handle := Handle;
Timer.Interval := AInterval;
Timer.OnTimer := AOnTimer;
Timer.Event := AEvent;
Event.data.ptr := Timer;
Event.events := EPOLLIN or EPOLLET;
if epoll_ctl(_TimerQueuePool.Handle, EPOLL_CTL_ADD, Handle, @Event) <> -1 then
begin
if _SetInterval(Handle, AInterval) then
begin
_TimersLock.Enter;
try
_Timers.Add(Handle, Timer);
finally
_TimersLock.Leave;
end;
Result := Handle;
end else Timer.Free; //if _SetInterval return false then the Timer in the EPOLL will be invalid
end else
begin
__close(Handle);
Timer.Free;
end;
end;
end;
`