Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
ccan
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mirror
ccan
Commits
a7f2b2c4
Commit
a7f2b2c4
authored
Oct 30, 2016
by
Rusty Russell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
time: timemono_add.
Signed-off-by:
Rusty Russell
<
rusty@rustcorp.com.au
>
parent
8b83ecf3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
ccan/time/test/run-monotonic.c
ccan/time/test/run-monotonic.c
+4
-1
ccan/time/time.h
ccan/time/time.h
+22
-0
No files found.
ccan/time/test/run-monotonic.c
View file @
a7f2b2c4
...
...
@@ -7,7 +7,7 @@ int main(void)
struct
timemono
t1
,
t2
;
struct
timerel
t3
;
plan_tests
(
3
);
plan_tests
(
5
);
/* Test time_mono */
t1
=
time_mono
();
...
...
@@ -21,5 +21,8 @@ int main(void)
ok1
(
time_less
(
timemono_between
(
t1
,
t2
),
t3
));
ok1
(
time_less
(
timemono_since
(
t1
),
t3
));
ok1
(
timemono_add
(
t1
,
t3
).
ts
.
tv_sec
==
t1
.
ts
.
tv_sec
+
1
);
ok1
(
timemono_add
(
t2
,
t3
).
ts
.
tv_nsec
==
t2
.
ts
.
tv_nsec
);
return
exit_status
();
}
ccan/time/time.h
View file @
a7f2b2c4
...
...
@@ -388,6 +388,28 @@ static inline struct timeabs timeabs_add(struct timeabs a, struct timerel b)
return
t
;
}
/**
* timemono_add - add a relative to a monotonic time
* @a: the monotonic time.
* @b: a relative time.
*
* The times must not overflow, or the results are undefined.
*
* Example:
* // We do one every second.
* static struct timemono next_timem(void)
* {
* return timemono_add(time_mono(), time_from_msec(1000));
* }
*/
static
inline
struct
timemono
timemono_add
(
struct
timemono
a
,
struct
timerel
b
)
{
struct
timemono
t
;
t
.
ts
=
time_add_
(
a
.
ts
,
b
.
ts
);
return
t
;
}
/**
* timerel_add - add two relative times
* @a: one relative time.
...
...
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