2 * Copyright (C) 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
4 * SPDX-License-Identifier: LGPL-2.1-only
10 #include <common/compat/errno.hpp>
11 #include <common/compat/time.hpp>
12 #include <common/macros.hpp>
13 #include <common/time.hpp>
22 #include <sys/types.h>
25 static inline int64_t elapsed_time_ns(struct timespec
*t1
, struct timespec
*t2
)
27 struct timespec delta
;
29 LTTNG_ASSERT(t1
&& t2
);
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
) + (int64_t) delta
.tv_nsec
;
35 int usleep_safe(useconds_t usec
)
38 struct timespec t1
, t2
;
39 int64_t time_remaining_ns
= (int64_t) usec
* (int64_t) NSEC_PER_USEC
;
41 ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &t1
);
44 perror("clock_gettime");
48 while (time_remaining_ns
> 0) {
49 ret
= usleep(time_remaining_ns
/ (int64_t) NSEC_PER_USEC
);
50 if (ret
&& errno
!= EINTR
) {
55 ret
= lttng_clock_gettime(CLOCK_MONOTONIC
, &t2
);
57 perror("clock_gettime");
61 time_remaining_ns
-= elapsed_time_ns(&t1
, &t2
);
67 int create_file(const char *path
)
75 ret
= creat(path
, S_IRWXU
);
90 int wait_on_file(const char *path
)
100 ret
= stat(path
, &buf
);
101 if (ret
== -1 && errno
== ENOENT
) {
102 ret
= poll(nullptr, 0, 10); /* 10 ms delay */
103 /* Should return 0 everytime */
108 fprintf(stderr
, "poll return value is larger than zero\n");
112 continue; /* retry */
This page took 0.034195 seconds and 4 git commands to generate.