return r;
if (arg_timeout > 0)
- timeout = now(CLOCK_MONOTONIC) + arg_timeout;
+ timeout = usec_add(now(CLOCK_MONOTONIC), arg_timeout);
else
timeout = 0;
/* 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 = {};
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 */
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)
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)
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)
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);
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);
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));
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);
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);
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
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) {
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) {
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;
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) {
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;
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);
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;
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)
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)
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)