27
27
28
28
using namespace trantor ;
29
29
#ifdef __linux__
30
- int createTimerfd ()
30
+ static int createTimerfd ()
31
31
{
32
32
int timerfd = ::timerfd_create (CLOCK_MONOTONIC, TFD_NONBLOCK | TFD_CLOEXEC);
33
33
if (timerfd < 0 )
@@ -37,7 +37,7 @@ int createTimerfd()
37
37
return timerfd;
38
38
}
39
39
40
- struct timespec howMuchTimeFromNow (const TimePoint &when)
40
+ static struct timespec howMuchTimeFromNow (const TimePoint &when)
41
41
{
42
42
auto microSeconds = std::chrono::duration_cast<std::chrono::microseconds>(
43
43
when - std::chrono::steady_clock::now ())
@@ -51,7 +51,7 @@ struct timespec howMuchTimeFromNow(const TimePoint &when)
51
51
ts.tv_nsec = static_cast <long >((microSeconds % 1000000 ) * 1000 );
52
52
return ts;
53
53
}
54
- void resetTimerfd (int timerfd, const TimePoint &expiration)
54
+ static void resetTimerfd (int timerfd, const TimePoint &expiration)
55
55
{
56
56
// wake up loop by timerfd_settime()
57
57
struct itimerspec newValue;
@@ -65,7 +65,7 @@ void resetTimerfd(int timerfd, const TimePoint &expiration)
65
65
// LOG_SYSERR << "timerfd_settime()";
66
66
}
67
67
}
68
- void readTimerfd (int timerfd, const TimePoint &now)
68
+ static void readTimerfd (int timerfd, const TimePoint &now)
69
69
{
70
70
uint64_t howmany;
71
71
ssize_t n = ::read (timerfd, &howmany, sizeof howmany);
@@ -99,7 +99,7 @@ void TimerQueue::handleRead()
99
99
reset (expired, now);
100
100
}
101
101
#else
102
- int64_t howMuchTimeFromNow (const TimePoint &when)
102
+ static int64_t howMuchTimeFromNow (const TimePoint &when)
103
103
{
104
104
auto microSeconds = std::chrono::duration_cast<std::chrono::microseconds>(
105
105
when - std::chrono::steady_clock::now ())
@@ -270,11 +270,18 @@ void TimerQueue::reset(const std::vector<TimerPtr> &expired,
270
270
loop_->assertInLoopThread ();
271
271
for (auto const &timerPtr : expired)
272
272
{
273
- if (timerPtr->isRepeat () &&
274
- timerIdSet_. find (timerPtr-> id ()) != timerIdSet_.end ())
273
+ auto iter = timerIdSet_. find (timerPtr->id ());
274
+ if (iter != timerIdSet_.end ())
275
275
{
276
- timerPtr->restart (now);
277
- insert (timerPtr);
276
+ if (timerPtr->isRepeat ())
277
+ {
278
+ timerPtr->restart (now);
279
+ insert (timerPtr);
280
+ }
281
+ else
282
+ {
283
+ timerIdSet_.erase (iter);
284
+ }
278
285
}
279
286
}
280
287
#ifdef __linux__
0 commit comments