Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
timeout.c
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
timeout.c
Commits
948cacb5
Commit
948cacb5
authored
Feb 26, 2016
by
William Ahern
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'nmathewson-fixing_intervals'
parents
a8a62b4f
43a85424
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
18 deletions
+37
-18
test-timeout.c
test-timeout.c
+30
-6
timeout.c
timeout.c
+7
-12
No files found.
test-timeout.c
View file @
948cacb5
...
...
@@ -226,6 +226,7 @@ struct intervals_cfg {
int
n_timeouts
;
timeout_t
start_at
;
timeout_t
end_at
;
timeout_t
skip
;
};
int
...
...
@@ -261,23 +262,35 @@ check_intervals(struct intervals_cfg *cfg)
while
(
now
<
cfg
->
end_at
)
{
timeout_t
delay
=
timeouts_timeout
(
tos
);
if
(
cfg
->
skip
&&
delay
<
cfg
->
skip
)
delay
=
cfg
->
skip
;
timeouts_step
(
tos
,
delay
);
now
+=
delay
;
while
(
NULL
!=
(
to
=
timeouts_get
(
tos
)))
{
i
=
to
-
&
t
[
0
];
assert
(
&
t
[
i
]
==
to
);
fired
[
i
]
++
;
if
(
0
!=
(
to
->
expires
-
cfg
->
start_at
)
%
cfg
->
timeouts
[
i
])
FAIL
();
if
(
to
->
expires
<=
now
)
FAIL
();
if
(
to
->
expires
>
now
+
cfg
->
timeouts
[
i
])
FAIL
();
}
if
(
!
timeouts_check
(
tos
,
stderr
))
FAIL
();
}
timeout_t
duration
=
cfg
->
end_at
-
cfg
->
start_at
;
timeout_t
duration
=
now
-
cfg
->
start_at
;
for
(
i
=
0
;
i
<
cfg
->
n_timeouts
;
++
i
)
{
if
(
cfg
->
skip
)
{
if
(
fired
[
i
]
>
duration
/
cfg
->
timeouts
[
i
])
FAIL
();
}
else
{
if
(
fired
[
i
]
!=
duration
/
cfg
->
timeouts
[
i
])
FAIL
();
}
if
(
!
timeout_pending
(
&
t
[
i
]))
FAIL
();
}
...
...
@@ -420,25 +433,36 @@ main(int argc, char **argv)
.
n_timeouts
=
sizeof
(
primes
)
/
sizeof
(
timeout_t
),
.
start_at
=
50
,
.
end_at
=
5322
,
.
skip
=
0
,
};
DO
(
check_intervals
(
&
icfg1
));
struct
intervals_cfg
icfg2
=
{
.
timeouts
=
primes
,
.
timeouts
=
factors_of_1337
,
.
n_timeouts
=
sizeof
(
factors_of_1337
)
/
sizeof
(
timeout_t
),
.
start_at
=
50
,
.
end_at
=
50000
,
.
skip
=
0
,
};
DO
(
check_intervals
(
&
icfg2
));
struct
intervals_cfg
icfg3
=
{
.
timeouts
=
primes
,
.
timeouts
=
multiples_of_five
,
.
n_timeouts
=
sizeof
(
multiples_of_five
)
/
sizeof
(
timeout_t
),
.
start_at
=
49
,
.
end_at
=
5333
,
.
skip
=
0
,
};
DO
(
check_intervals
(
&
icfg3
));
struct
intervals_cfg
icfg4
=
{
.
timeouts
=
primes
,
.
n_timeouts
=
sizeof
(
primes
)
/
sizeof
(
timeout_t
),
.
start_at
=
50
,
.
end_at
=
5322
,
.
skip
=
16
,
};
DO
(
check_intervals
(
&
icfg4
));
if
(
n_failed
)
{
puts
(
"
\n
FAIL"
);
...
...
timeout.c
View file @
948cacb5
...
...
@@ -358,18 +358,13 @@ static void timeouts_readd(struct timeouts *T, struct timeout *to) {
to
->
expires
+=
to
->
interval
;
if
(
to
->
expires
<=
T
->
curtime
)
{
if
(
to
->
expires
<
T
->
curtime
)
{
/* If we've missed the next firing of this timeout, reschedule
* it to occur at the next multiple of its interval after
* the last time that it fired.
*/
timeout_t
n
=
T
->
curtime
-
to
->
expires
;
timeout_t
q
=
n
/
to
->
interval
;
timeout_t
r
=
n
%
to
->
interval
;
if
(
r
)
to
->
expires
+=
(
to
->
interval
*
q
)
+
(
to
->
interval
-
r
);
else
to
->
expires
+=
(
to
->
interval
*
q
);
}
else
{
to
->
expires
+=
to
->
interval
;
}
to
->
expires
=
T
->
curtime
+
(
to
->
interval
-
r
);
}
timeouts_sched
(
T
,
to
,
to
->
expires
);
...
...
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