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.c
Go to the documentation of this file.
1 /*
2  * APPLE Compatibility
3  */
4 
5 #ifdef __APPLE__
6 
7 #include <pthread.h>
8 #include <errno.h>
9 
10 #include "apple_compat.h"
11 
12 int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
13 {
14  if(count == 0)
15  {
16  errno = EINVAL;
17  return -1;
18  }
19  if(pthread_mutex_init(&barrier->mutex, 0) < 0)
20  {
21  return -1;
22  }
23  if(pthread_cond_init(&barrier->cond, 0) < 0)
24  {
25  pthread_mutex_destroy(&barrier->mutex);
26  return -1;
27  }
28  barrier->tripCount = count;
29  barrier->count = 0;
30 
31  return 0;
32 }
33 
34 int pthread_barrier_destroy(pthread_barrier_t *barrier)
35 {
36  pthread_cond_destroy(&barrier->cond);
37  pthread_mutex_destroy(&barrier->mutex);
38  return 0;
39 }
40 
41 int pthread_barrier_wait(pthread_barrier_t *barrier)
42 {
43  pthread_mutex_lock(&barrier->mutex);
44  ++(barrier->count);
45  if(barrier->count >= barrier->tripCount)
46  {
47  barrier->count = 0;
48  pthread_cond_broadcast(&barrier->cond);
49  pthread_mutex_unlock(&barrier->mutex);
50  return 1;
51  }
52  else
53  {
54  pthread_cond_wait(&barrier->cond, &(barrier->mutex));
55  pthread_mutex_unlock(&barrier->mutex);
56  return 0;
57  }
58 }
59 
60 #endif // __APPLE_