Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
L
libzmq
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
libzmq
Commits
19a70ab6
Commit
19a70ab6
authored
Aug 07, 2018
by
Simon Giesecke
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Optimized and simplified zmq::timers_t::execute and zmq::timers_t::timeout
parent
4f77cfa3
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
45 deletions
+30
-45
timers.cpp
src/timers.cpp
+30
-45
No files found.
src/timers.cpp
View file @
19a70ab6
...
...
@@ -135,65 +135,50 @@ int zmq::timers_t::reset (int timer_id_)
long
zmq
::
timers_t
::
timeout
()
{
timersmap_t
::
iterator
it
=
_timers
.
begin
();
uint64_t
now
=
_clock
.
now_ms
();
while
(
it
!=
_timers
.
end
())
{
cancelled_timers_t
::
iterator
cancelled_it
=
_cancelled_timers
.
find
(
it
->
second
.
timer_id
);
// Live timer, lets return the timeout
if
(
cancelled_it
==
_cancelled_timers
.
end
())
{
if
(
it
->
first
>
now
)
return
static_cast
<
long
>
(
it
->
first
-
now
);
const
uint64_t
now
=
_clock
.
now_ms
();
long
res
=
-
1
;
return
0
;
const
timersmap_t
::
iterator
begin
=
_timers
.
begin
();
const
timersmap_t
::
iterator
end
=
_timers
.
end
();
timersmap_t
::
iterator
it
=
begin
;
for
(;
it
!=
end
;
++
it
)
{
if
(
0
==
_cancelled_timers
.
erase
(
it
->
second
.
timer_id
))
{
// Live timer, lets return the timeout
res
=
it
->
first
>
now
?
static_cast
<
long
>
(
it
->
first
-
now
)
:
0
;
break
;
}
// Let's remove it from the beginning of the list
timersmap_t
::
iterator
old
=
it
;
++
it
;
_timers
.
erase
(
old
);
_cancelled_timers
.
erase
(
cancelled_it
);
}
// Wait forever as no timers are alive
return
-
1
;
// Remove timed-out timers
_timers
.
erase
(
begin
,
it
);
return
res
;
}
int
zmq
::
timers_t
::
execute
()
{
timersmap_t
::
iterator
it
=
_timers
.
begin
();
uint64_t
now
=
_clock
.
now_ms
();
while
(
it
!=
_timers
.
end
())
{
cancelled_timers_t
::
iterator
cancelled_it
=
_cancelled_timers
.
find
(
it
->
second
.
timer_id
);
const
uint64_t
now
=
_clock
.
now_ms
();
// Dead timer, lets remove it and continue
if
(
cancelled_it
!=
_cancelled_timers
.
end
())
{
timersmap_t
::
iterator
old
=
it
;
++
it
;
_timers
.
erase
(
old
);
_cancelled_timers
.
erase
(
cancelled_it
);
continue
;
}
const
timersmap_t
::
iterator
begin
=
_timers
.
begin
();
const
timersmap_t
::
iterator
end
=
_timers
.
end
();
timersmap_t
::
iterator
it
=
_timers
.
begin
();
for
(;
it
!=
end
;
++
it
)
{
if
(
0
==
_cancelled_timers
.
erase
(
it
->
second
.
timer_id
))
{
// Timer is not cancelled
// Map is ordered, if we have to wait for current timer we can stop.
if
(
it
->
first
>
now
)
break
;
// Map is ordered, if we have to wait for current timer we can stop.
if
(
it
->
first
>
now
)
break
;
timer_t
timer
=
it
->
second
;
const
timer_t
&
timer
=
it
->
second
;
timer
.
handler
(
timer
.
timer_id
,
timer
.
arg
);
timer
.
handler
(
timer
.
timer_id
,
timer
.
arg
);
timersmap_t
::
iterator
old
=
it
;
++
it
;
_timers
.
erase
(
old
);
_timers
.
insert
(
timersmap_t
::
value_type
(
now
+
timer
.
interval
,
timer
));
_timers
.
insert
(
timersmap_t
::
value_type
(
now
+
timer
.
interval
,
timer
));
}
}
_timers
.
erase
(
begin
,
it
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment