summaryrefslogtreecommitdiff
path: root/src/cgtop
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2021-03-03 12:56:52 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2021-03-05 07:10:08 +0900
commit496db330041151138809c8f8579fa91d7897aabe (patch)
tree865ff3fde1989e4bf931da2563dfd3315401f3e9 /src/cgtop
parente6283cbf48a3821d03ec73252620fc1b04bd4588 (diff)
downloadsystemd-496db330041151138809c8f8579fa91d7897aabe.tar.gz
tree-wide: use usec_add() and usec_sub_unsigned()
Diffstat (limited to 'src/cgtop')
-rw-r--r--src/cgtop/cgtop.c15
1 files changed, 5 insertions, 10 deletions
diff --git a/src/cgtop/cgtop.c b/src/cgtop/cgtop.c
index cbae9897a5..29817224ad 100644
--- a/src/cgtop/cgtop.c
+++ b/src/cgtop/cgtop.c
@@ -953,7 +953,7 @@ static int run(int argc, char *argv[]) {
t = now(CLOCK_MONOTONIC);
- if (t >= last_refresh + arg_delay || immediate_refresh) {
+ if (t >= usec_add(last_refresh, arg_delay) || immediate_refresh) {
r = refresh(root, a, b, iteration++);
if (r < 0)
@@ -976,9 +976,9 @@ static int run(int argc, char *argv[]) {
fflush(stdout);
if (arg_batch)
- (void) usleep(last_refresh + arg_delay - t);
+ (void) usleep(usec_add(usec_sub_unsigned(last_refresh, t), arg_delay));
else {
- r = read_one_char(stdin, &key, last_refresh + arg_delay - t, NULL);
+ r = read_one_char(stdin, &key, usec_add(usec_sub_unsigned(last_refresh, t), arg_delay), NULL);
if (r == -ETIMEDOUT)
continue;
if (r < 0)
@@ -1053,10 +1053,7 @@ static int run(int argc, char *argv[]) {
break;
case '+':
- if (arg_delay < USEC_PER_SEC)
- arg_delay += USEC_PER_MSEC*250;
- else
- arg_delay += USEC_PER_SEC;
+ arg_delay = usec_add(arg_delay, arg_delay < USEC_PER_SEC ? USEC_PER_MSEC * 250 : USEC_PER_SEC);
fprintf(stdout, "\nIncreased delay to %s.", format_timespan(h, sizeof(h), arg_delay, 0));
fflush(stdout);
@@ -1066,10 +1063,8 @@ static int run(int argc, char *argv[]) {
case '-':
if (arg_delay <= USEC_PER_MSEC*500)
arg_delay = USEC_PER_MSEC*250;
- else if (arg_delay < USEC_PER_MSEC*1250)
- arg_delay -= USEC_PER_MSEC*250;
else
- arg_delay -= USEC_PER_SEC;
+ arg_delay = usec_sub_unsigned(arg_delay, arg_delay < USEC_PER_MSEC * 1250 ? USEC_PER_MSEC * 250 : USEC_PER_SEC);
fprintf(stdout, "\nDecreased delay to %s.", format_timespan(h, sizeof(h), arg_delay, 0));
fflush(stdout);