History

Add clock_nanosleep emulation for macOS

Christian Jullien committed 6 years ago

Commit 9ad25d71 parent 925f6701 file · +46 −0Browse files

Unified · Split

tests/tests2/114_bound_signal.c+46−0
@@ -8,6 +8,52 @@ · 7 unmodified lines
8#include <errno.h>8#include <errno.h>
9#include <setjmp.h>9#include <setjmp.h>
10 10
11#if defined(__APPLE__)
12/*
13 * clock_nanosleep is missing on all macOS version, add emulation.
14 */
15
16/* scale factors */
17#define TIMING_GIGA 1000000000
18#define TIMER_ABSTIME 0 /* not used */
19
20/* timespec difference (monotonic) right - left */
21static inline void
22timespec_monodiff_rml(struct timespec *ts_out, const struct timespec *ts_in) {
23 /*
24 * out = in - out,
25 * where in > out
26 */
27 ts_out->tv_sec = ts_in->tv_sec - ts_out->tv_sec;
28 ts_out->tv_nsec = ts_in->tv_nsec - ts_out->tv_nsec;
29 if (ts_out->tv_sec < 0) {
30 ts_out->tv_sec = 0;
31 ts_out->tv_nsec = 0;
32 } else if (ts_out->tv_nsec < 0) {
33 if (ts_out->tv_sec == 0) {
34 ts_out->tv_sec = 0;
35 ts_out->tv_nsec = 0;
36 } else {
37 ts_out->tv_sec = ts_out->tv_sec - 1;
38 ts_out->tv_nsec = ts_out->tv_nsec + TIMING_GIGA;
39 }
40 }
41}
42
43static inline int
44clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *req, struct timespec *remain) {
45 struct timespec ts_delta;
46 int retval = clock_gettime(clock_id, &ts_delta);
47 (void)remain;
48 (void)flags;
49 if (retval == 0) {
50 timespec_monodiff_rml(&ts_delta, req);
51 retval = nanosleep(&ts_delta, NULL);
52 }
53 return retval;
54}
55#endif
56
11static volatile int run = 1;57static volatile int run = 1;
12static int dummy[10];58static int dummy[10];
13static sem_t sem;59static sem_t sem;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t