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

定时器中的resetArriveTime(),不应该是以第一个TimerEvent的arrivedTime作为Timer的新的arrivedTime吗?(应该是auto it = tmp.begin(),而不是auto it = tmp.rbegin()) #72

Open
JanDavi opened this issue Feb 27, 2024 · 1 comment

Comments

@JanDavi
Copy link

JanDavi commented Feb 27, 2024

void Timer::resetArriveTime() {
  RWMutex::ReadLock lock(m_event_mutex);
  std::multimap<int64_t, TimerEvent::ptr> tmp = m_pending_events;
  lock.unlock();

  if (tmp.size() == 0) {
    DebugLog << "no timerevent pending, size = 0";
    return;
  }

  auto it = tmp.rbegin();
  int64_t interval = (*it).first - getNowMs();
  if (interval < 0) {
    DebugLog << "all timer events has already expire";
    return;
  }

  timespec ts;
  memset(&ts, 0, sizeof(ts));
  ts.tv_sec = interval / 1000;
  ts.tv_nsec = (interval % 1000) * 1000000;
  
  itimerspec new_value;
  memset(&new_value, 0, sizeof(new_value));
  new_value.it_value = ts;

  int rt = timerfd_settime(m_fd, 0, &new_value, nullptr);

  if (rt != 0) {
    ErrorLog << "tiemr_settime error, interval=" << interval;
  } else {
    DebugLog << "reset timer succ, next occur time=" << (*it).first;
  }
}
@AIGC-yuxincai
Copy link

AIGC-yuxincai commented Feb 27, 2024 via email

@JanDavi JanDavi changed the title 定时器中的resetArriveTime(),不应该是以第一个TimerEvent的arrivedTime作为Timer的新的arrivedTime吗?(应该是auto it = tmp.begin();,而不是auto it = tmp.rbegin();) 定时器中的resetArriveTime(),不应该是以第一个TimerEvent的arrivedTime作为Timer的新的arrivedTime吗?(应该是auto it = tmp.begin(),而不是auto it = tmp.rbegin()) Feb 27, 2024
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

2 participants