Skip to content

Issue about dwsXPlatformTimer #15

Open

Description

@achinastone

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…

Activity

  1. achinastone commented on Oct 29, 2024

    @achinastone
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions