Gooddbird / tinyrpc

c++ async rpc framework. 14w+qps.
Apache License 2.0
1.29k stars 189 forks source link

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

Open JanDavi opened 8 months ago

JanDavi commented 8 months ago
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 commented 8 months ago

您好,已收到您的来信,谢谢!