2 * Copyright (C) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
9 #include <common/compat/time.h>
10 #include <common/time.h>
19 #include <sys/types.h>
25 int64_t elapsed_time_ns(struct timespec
*t1
, struct timespec
*t2
)
27 struct timespec delta
;
30 delta
.tv_sec
= t2
->tv_sec
- t1
->tv_sec
;
31 delta
.tv_nsec
= t2
->tv_nsec
- t1
->tv_nsec
;
32 return ((int64_t) NSEC_PER_SEC
* (int64_t) delta
.tv_sec
) +
33 (int64_t) delta
.tv_nsec
;
36 int usleep_safe(useconds_t usec
)
39 struct timespec t1
, t2
;
40 int64_t time_remaining_ns
= (int64_t) usec
* (int64_t) NSEC_PER_USEC
;
42 ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &t1
);
45 perror("clock_gettime");
49 while (time_remaining_ns
> 0) {
50 ret
= usleep(time_remaining_ns
/ (int64_t) NSEC_PER_USEC
);
51 if (ret
&& errno
!= EINTR
) {
56 ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &t2
);
58 perror("clock_gettime");
62 time_remaining_ns
-= elapsed_time_ns(&t1
, &t2
);
68 int create_file(const char *path
)
76 ret
= creat(path
, S_IRWXU
);
91 int wait_on_file(const char *path
)
101 ret
= stat(path
, &buf
);
102 if (ret
== -1 && errno
== ENOENT
) {
103 ret
= poll(NULL
, 0, 10); /* 10 ms delay */
104 /* Should return 0 everytime */
110 "poll return value is larger than zero\n");
114 continue; /* retry */
This page took 0.036326 seconds and 4 git commands to generate.