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

Enable emplace feature for timers #4719

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading