Skip to content

Commit

Permalink
Enable emplace feature for timers
Browse files Browse the repository at this point in the history
  • Loading branch information
githejie committed Aug 3, 2024
1 parent b95d949 commit 87e17b1
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/timers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "precompiled.hpp"
#include "timers.hpp"
#include "blob.hpp"
#include "err.hpp"

#include <algorithm>
Expand Down Expand Up @@ -30,7 +31,7 @@ int zmq::timers_t::add (size_t interval_, timers_timer_fn handler_, void *arg_)

uint64_t when = _clock.now_ms () + interval_;
timer_t timer = {++_next_timer_id, interval_, handler_, arg_};
_timers.insert (timersmap_t::value_type (when, timer));
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer);

return timer.timer_id;
}
Expand Down Expand Up @@ -79,7 +80,7 @@ int zmq::timers_t::set_interval (int timer_id_, size_t interval_)
timer.interval = interval_;
uint64_t when = _clock.now_ms () + interval_;
_timers.erase (it);
_timers.insert (timersmap_t::value_type (when, timer));
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer);

return 0;
}
Expand All @@ -97,7 +98,7 @@ int zmq::timers_t::reset (int timer_id_)
timer_t timer = it->second;
uint64_t when = _clock.now_ms () + timer.interval;
_timers.erase (it);
_timers.insert (timersmap_t::value_type (when, timer));
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (when, timer);

return 0;
}
Expand Down Expand Up @@ -147,8 +148,7 @@ int zmq::timers_t::execute ()

timer.handler (timer.timer_id, timer.arg);

_timers.insert (
timersmap_t::value_type (now + timer.interval, timer));
_timers.ZMQ_MAP_INSERT_OR_EMPLACE (now + timer.interval, timer);
}
}
_timers.erase (begin, it);
Expand Down

0 comments on commit 87e17b1

Please sign in to comment.