SDRAngel  4.11.5
Developer docs for <a href="https://github.com/f4exb/sdrangel">SDRangel<\a>, an Open Source Qt5 / OpenGL 3.0+ SDR and signal analyzer frontend to various hardware.
apple_compat.h
Go to the documentation of this file.
1 /*
2  * APPLE Compatibility
3  */
4 
5 #ifdef __APPLE__
6 
10 #ifndef PTHREAD_BARRIER_H_
11 #define PTHREAD_BARRIER_H_
12 
13 #include <pthread.h>
14 #include <errno.h>
15 
16 typedef int pthread_barrierattr_t;
17 typedef struct
18 {
19  pthread_mutex_t mutex;
20  pthread_cond_t cond;
21  int count;
22  int tripCount;
23 } pthread_barrier_t;
24 
25 
26 int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count);
27 
28 int pthread_barrier_destroy(pthread_barrier_t *barrier);
29 
30 int pthread_barrier_wait(pthread_barrier_t *barrier);
31 
32 #endif // PTHREAD_BARRIER_H_
33 
34 
35 // macOS < 10.12 doesn't have clock_gettime()
36 #include <time.h>
37 #if !defined(CLOCK_REALTIME) && !defined(CLOCK_MONOTONIC)
38 
39 #define CLOCK_REALTIME 0
40 #define CLOCK_MONOTONIC 6
41 typedef int clockid_t;
42 
43 #include <sys/time.h>
44 #include <mach/mach_time.h>
45 
46 // here to avoid problem on linking of qrtplib
47 inline int clock_gettime( clockid_t clk_id, struct timespec *ts )
48 {
49  int ret = -1;
50  if ( ts )
51  {
52  if ( CLOCK_REALTIME == clk_id )
53  {
54  struct timeval tv;
55  ret = gettimeofday(&tv, NULL);
56  ts->tv_sec = tv.tv_sec;
57  ts->tv_nsec = tv.tv_usec * 1000;
58  }
59  else if ( CLOCK_MONOTONIC == clk_id )
60  {
61  const uint64_t t = mach_absolute_time();
62  mach_timebase_info_data_t timebase;
63  mach_timebase_info(&timebase);
64  const uint64_t tdiff = t * timebase.numer / timebase.denom;
65  ts->tv_sec = tdiff / 1000000000;
66  ts->tv_nsec = tdiff % 1000000000;
67  ret = 0;
68  }
69  }
70  return ret;
71 }
72 
73 #endif // CLOCK_REALTIME and CLOCK_MONOTONIC
74 
75 #endif // __APPLE__
unsigned __int64 uint64_t
Definition: rtptypes_win.h:48