summarylogtreecommitdiffstats
path: root/0001-android-pthread-barrier.patch
blob: fdf74e6017d461a1a3feaf6d95a818501741783c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
--- a/libusb/hidapi_thread_pthread.h
+++ a/libusb/hidapi_thread_pthread.h
@@ -29,15 +29,17 @@
 /* Barrier implementation because Android/Bionic don't have pthread_barrier.
    This implementation came from Brent Priddy and was posted on
    StackOverflow. It is used with his permission. */
+#define pthr_barrier_t hidapi_pthread_barrier_t
+
 typedef int pthread_barrierattr_t;
-typedef struct pthread_barrier {
+typedef struct hidapi_pthread_barrier_t {
     pthread_mutex_t mutex;
     pthread_cond_t cond;
     int count;
     int trip_count;
-} pthread_barrier_t;
+} hidapi_pthread_barrier_t;
 
-static int pthread_barrier_init(pthread_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
+static int pthread_barrier_init(pthr_barrier_t *barrier, const pthread_barrierattr_t *attr, unsigned int count)
 {
 	if(count == 0) {
 		errno = EINVAL;
@@ -57,14 +59,14 @@
 	return 0;
 }
 
-static int pthread_barrier_destroy(pthread_barrier_t *barrier)
+static int pthread_barrier_destroy(pthr_barrier_t *barrier)
 {
 	pthread_cond_destroy(&barrier->cond);
 	pthread_mutex_destroy(&barrier->mutex);
 	return 0;
 }
 
-static int pthread_barrier_wait(pthread_barrier_t *barrier)
+static int pthread_barrier_wait(pthr_barrier_t *barrier)
 {
 	pthread_mutex_lock(&barrier->mutex);
 	++(barrier->count);
@@ -80,7 +82,8 @@
 		return 0;
 	}
 }
-
+#else
+	#define pthr_barrier_t pthread_barrier_t
 #endif
 
 #define HIDAPI_THREAD_TIMED_OUT	ETIMEDOUT
@@ -92,7 +95,7 @@
 	pthread_t thread;
 	pthread_mutex_t mutex; /* Protects input_reports */
 	pthread_cond_t condition;
-	pthread_barrier_t barrier; /* Ensures correct startup sequence */
+	pthr_barrier_t barrier; /* Ensures correct startup sequence */
 
 } hidapi_thread_state;