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>
18 #include <sys/types.h>
21 #include <common/compat/errno.h>
26 int64_t elapsed_time_ns(struct timespec
*t1
, struct timespec
*t2
)
28 struct timespec delta
;
31 delta
.tv_sec
= t2
->tv_sec
- t1
->tv_sec
;
32 delta
.tv_nsec
= t2
->tv_nsec
- t1
->tv_nsec
;
33 return ((int64_t) NSEC_PER_SEC
* (int64_t) delta
.tv_sec
) +
34 (int64_t) delta
.tv_nsec
;
37 int usleep_safe(useconds_t usec
)
40 struct timespec t1
, t2
;
41 int64_t time_remaining_ns
= (int64_t) usec
* (int64_t) NSEC_PER_USEC
;
43 ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &t1
);
46 perror("clock_gettime");
50 while (time_remaining_ns
> 0) {
51 ret
= usleep(time_remaining_ns
/ (int64_t) NSEC_PER_USEC
);
52 if (ret
&& errno
!= EINTR
) {
57 ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &t2
);
59 perror("clock_gettime");
63 time_remaining_ns
-= elapsed_time_ns(&t1
, &t2
);
69 int create_file(const char *path
)
77 ret
= creat(path
, S_IRWXU
);
92 int wait_on_file(const char *path
)
102 ret
= stat(path
, &buf
);
103 if (ret
== -1 && errno
== ENOENT
) {
104 ret
= poll(NULL
, 0, 10); /* 10 ms delay */
105 /* Should return 0 everytime */
111 "poll return value is larger than zero\n");
115 continue; /* retry */
This page took 0.033139 seconds and 4 git commands to generate.