Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue about dwsXPlatformTimer #15

Open
achinastone opened this issue Oct 29, 2024 · 1 comment
Open

Issue about dwsXPlatformTimer #15

achinastone opened this issue Oct 29, 2024 · 1 comment

Comments

@achinastone
Copy link

I have mentioned the problem about Timer( May be nil).
The more serious problem is the Timer maybe a invalid value but not nil.
Uploading Bug.png…

@achinastone
Copy link
Author

`
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;
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant