mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-02-04 17:47:03 +03:00
tree-wide: use usec_add() and usec_sub_unsigned()
This commit is contained in:
parent
e6283cbf48
commit
496db33004
@ -166,7 +166,7 @@ static int run(int argc, char *argv[]) {
|
||||
return r;
|
||||
|
||||
if (arg_timeout > 0)
|
||||
timeout = now(CLOCK_MONOTONIC) + arg_timeout;
|
||||
timeout = usec_add(now(CLOCK_MONOTONIC), arg_timeout);
|
||||
else
|
||||
timeout = 0;
|
||||
|
||||
|
@ -756,7 +756,7 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) {
|
||||
|
||||
/* Drop into a sigtimewait-based timeout. Waiting for the
|
||||
* pid to exit. */
|
||||
until = now(CLOCK_MONOTONIC) + timeout;
|
||||
until = usec_add(now(CLOCK_MONOTONIC), timeout);
|
||||
for (;;) {
|
||||
usec_t n;
|
||||
siginfo_t status = {};
|
||||
|
@ -19,7 +19,7 @@ bool ratelimit_below(RateLimit *r) {
|
||||
ts = now(CLOCK_MONOTONIC);
|
||||
|
||||
if (r->begin <= 0 ||
|
||||
ts - r->begin > r->interval) {
|
||||
usec_sub_unsigned(ts, r->begin) > r->interval) {
|
||||
r->begin = ts;
|
||||
|
||||
/* Reset counter */
|
||||
|
@ -440,11 +440,11 @@ int acquire_terminal(
|
||||
|
||||
assert(ts != USEC_INFINITY);
|
||||
|
||||
n = now(CLOCK_MONOTONIC);
|
||||
if (ts + timeout < n)
|
||||
n = usec_sub_unsigned(now(CLOCK_MONOTONIC), ts);
|
||||
if (n >= timeout)
|
||||
return -ETIMEDOUT;
|
||||
|
||||
r = fd_wait_for_event(notify, POLLIN, ts + timeout - n);
|
||||
r = fd_wait_for_event(notify, POLLIN, usec_sub_unsigned(timeout, n));
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0)
|
||||
|
@ -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);
|
||||
|
@ -1503,10 +1503,9 @@ static int run(int argc, char *argv[]) {
|
||||
|
||||
flags = determine_flags();
|
||||
|
||||
if (arg_timeout == USEC_INFINITY)
|
||||
until = usec_add(now(CLOCK_MONOTONIC), arg_timeout);
|
||||
if (until == USEC_INFINITY)
|
||||
until = 0;
|
||||
else
|
||||
until = now(CLOCK_MONOTONIC) + arg_timeout;
|
||||
|
||||
arg_key_size = (arg_key_size > 0 ? arg_key_size : (256 / 8));
|
||||
|
||||
|
@ -144,7 +144,7 @@ static int cache_space_refresh(Server *s, JournalStorage *storage) {
|
||||
|
||||
ts = now(CLOCK_MONOTONIC);
|
||||
|
||||
if (space->timestamp != 0 && space->timestamp + RECHECK_SPACE_USEC > ts)
|
||||
if (space->timestamp != 0 && usec_add(space->timestamp, RECHECK_SPACE_USEC) > ts)
|
||||
return 0;
|
||||
|
||||
r = determine_path_usage(s, storage->path, &vfs_used, &vfs_avail);
|
||||
@ -1206,7 +1206,7 @@ finish:
|
||||
server_driver_message(s, 0, NULL,
|
||||
LOG_MESSAGE("Time spent on flushing to %s is %s for %u entries.",
|
||||
s->system_storage.path,
|
||||
format_timespan(ts, sizeof(ts), now(CLOCK_MONOTONIC) - start, 0),
|
||||
format_timespan(ts, sizeof(ts), usec_sub_unsigned(now(CLOCK_MONOTONIC), start), 0),
|
||||
n),
|
||||
NULL);
|
||||
|
||||
|
@ -2205,7 +2205,9 @@ _public_ int sd_bus_send_to(sd_bus *bus, sd_bus_message *m, const char *destinat
|
||||
static usec_t calc_elapse(sd_bus *bus, uint64_t usec) {
|
||||
assert(bus);
|
||||
|
||||
if (usec == (uint64_t) -1)
|
||||
assert_cc(sizeof(usec_t) == sizeof(uint64_t));
|
||||
|
||||
if (usec == USEC_INFINITY)
|
||||
return 0;
|
||||
|
||||
/* We start all timeouts the instant we enter BUS_HELLO/BUS_RUNNING state, so that the don't run in parallel
|
||||
@ -2215,7 +2217,7 @@ static usec_t calc_elapse(sd_bus *bus, uint64_t usec) {
|
||||
if (IN_SET(bus->state, BUS_WATCH_BIND, BUS_OPENING, BUS_AUTHENTICATING))
|
||||
return usec;
|
||||
else
|
||||
return now(CLOCK_MONOTONIC) + usec;
|
||||
return usec_add(now(CLOCK_MONOTONIC), usec);
|
||||
}
|
||||
|
||||
static int timeout_compare(const void *a, const void *b) {
|
||||
|
@ -2594,10 +2594,11 @@ _public_ int sd_event_source_set_time_relative(sd_event_source *s, uint64_t usec
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (usec >= USEC_INFINITY - t)
|
||||
usec = usec_add(t, usec);
|
||||
if (usec == USEC_INFINITY)
|
||||
return -EOVERFLOW;
|
||||
|
||||
return sd_event_source_set_time(s, t + usec);
|
||||
return sd_event_source_set_time(s, usec);
|
||||
}
|
||||
|
||||
_public_ int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec) {
|
||||
|
@ -2725,10 +2725,7 @@ _public_ int sd_journal_wait(sd_journal *j, uint64_t timeout_usec) {
|
||||
return r;
|
||||
|
||||
if (t != (uint64_t) -1) {
|
||||
usec_t n;
|
||||
|
||||
n = now(CLOCK_MONOTONIC);
|
||||
t = t > n ? t - n : 0;
|
||||
t = usec_sub_unsigned(t, now(CLOCK_MONOTONIC));
|
||||
|
||||
if (timeout_usec == (uint64_t) -1 || timeout_usec > t)
|
||||
timeout_usec = t;
|
||||
|
@ -518,7 +518,7 @@ static usec_t calc_elapse(uint64_t usec) {
|
||||
if (usec == 0)
|
||||
usec = RTNL_DEFAULT_TIMEOUT;
|
||||
|
||||
return now(CLOCK_MONOTONIC) + usec;
|
||||
return usec_add(now(CLOCK_MONOTONIC), usec);
|
||||
}
|
||||
|
||||
static int rtnl_poll(sd_netlink *rtnl, bool need_more, uint64_t timeout_usec) {
|
||||
|
@ -1637,7 +1637,7 @@ static int execute_shutdown_or_sleep(
|
||||
m->action_what = w;
|
||||
|
||||
/* Make sure the lid switch is ignored for a while */
|
||||
manager_set_lid_switch_ignore(m, now(CLOCK_MONOTONIC) + m->holdoff_timeout_usec);
|
||||
manager_set_lid_switch_ignore(m, usec_add(now(CLOCK_MONOTONIC), m->holdoff_timeout_usec));
|
||||
|
||||
return 0;
|
||||
|
||||
|
@ -535,7 +535,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
route->pref = preference;
|
||||
route->gw_family = AF_INET6;
|
||||
route->gw = gateway;
|
||||
route->lifetime = time_now + lifetime * USEC_PER_SEC;
|
||||
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
|
||||
route->mtu = mtu;
|
||||
|
||||
r = ndisc_route_configure(route, link, rt);
|
||||
@ -559,7 +559,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) {
|
||||
route_gw->protocol = RTPROT_RA;
|
||||
if (!route_gw->pref_set)
|
||||
route->pref = preference;
|
||||
route_gw->lifetime = time_now + lifetime * USEC_PER_SEC;
|
||||
route_gw->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
|
||||
if (route_gw->mtu == 0)
|
||||
route_gw->mtu = mtu;
|
||||
|
||||
@ -818,7 +818,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) {
|
||||
route->protocol = RTPROT_RA;
|
||||
route->flags = RTM_F_PREFIX;
|
||||
route->dst_prefixlen = prefixlen;
|
||||
route->lifetime = time_now + lifetime * USEC_PER_SEC;
|
||||
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
|
||||
|
||||
r = sd_ndisc_router_prefix_get_address(rt, &route->dst.in6);
|
||||
if (r < 0)
|
||||
@ -906,7 +906,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) {
|
||||
route->gw_family = AF_INET6;
|
||||
route->dst = dst;
|
||||
route->dst_prefixlen = prefixlen;
|
||||
route->lifetime = time_now + lifetime * USEC_PER_SEC;
|
||||
route->lifetime = usec_add(time_now, lifetime * USEC_PER_SEC);
|
||||
|
||||
r = ndisc_route_configure(route, link, rt);
|
||||
if (r < 0)
|
||||
|
@ -325,7 +325,7 @@ int manager_new(Manager **ret, Hashmap *interfaces, char **ignore,
|
||||
if (timeout > 0) {
|
||||
usec_t usec;
|
||||
|
||||
usec = now(clock_boottime_or_monotonic()) + timeout;
|
||||
usec = usec_add(now(clock_boottime_or_monotonic()), timeout);
|
||||
|
||||
r = sd_event_add_time(m->event, NULL, clock_boottime_or_monotonic(), usec, 0, NULL, INT_TO_PTR(-ETIMEDOUT));
|
||||
if (r < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user