File: 0018-Workaround-a-nasty-libpthread-bug-on-Windows-when-th.patch

package info (click to toggle)
airspyone-host 1.0.10-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,200 kB
  • sloc: ansic: 6,550; sh: 31; xml: 20; makefile: 2
file content (131 lines) | stat: -rw-r--r-- 3,528 bytes parent folder | download
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From 099256fd5e3ec29a3513fb047e041a4ec3257f95 Mon Sep 17 00:00:00 2001
From: Youssef <youssef@airspy.com>
Date: Mon, 11 Dec 2023 20:40:21 +0100
Subject: [PATCH 18/29] Workaround a nasty libpthread bug on Windows when the
 process is run with a different working directory than the exe; Cleaned up
 the streaming logic.

---
 libairspy/src/airspy.c | 36 ++++++++++++++++++------------------
 libairspy/src/airspy.h |  4 ++--
 2 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/libairspy/src/airspy.c b/libairspy/src/airspy.c
index 1c53c06..ba39e05 100644
--- a/libairspy/src/airspy.c
+++ b/libairspy/src/airspy.c
@@ -426,16 +426,16 @@ static void* consumer_threadproc(void *arg)
 
 		if (device->callback(&transfer) != 0)
 		{
-			device->stop_requested = true;
+			device->streaming = false;
 		}
 
 		pthread_mutex_lock(&device->consumer_mp);
 		device->received_buffer_count--;
 	}
 
-	pthread_mutex_unlock(&device->consumer_mp);
+	device->streaming = false;
 
-	pthread_exit(NULL);
+	pthread_mutex_unlock(&device->consumer_mp);
 
 	return NULL;
 }
@@ -477,12 +477,12 @@ static void airspy_libusb_transfer_callback(struct libusb_transfer* usb_transfer
 
 		if (libusb_submit_transfer(usb_transfer) != 0)
 		{
-			device->stop_requested = true;
+			device->streaming = false;
 		}
 	}
 	else
 	{
-		device->stop_requested = true;
+		device->streaming = false;
 	}
 }
 
@@ -504,11 +504,11 @@ static void* transfer_threadproc(void* arg)
 		if (error < 0)
 		{
 			if (error != LIBUSB_ERROR_INTERRUPTED)
-				device->stop_requested = true;
+				device->streaming = false;
 		}
 	}
-
-	pthread_exit(NULL);
+	
+	device->streaming = false;
 
 	return NULL;
 }
@@ -517,9 +517,10 @@ static int kill_io_threads(airspy_device_t* device)
 {
 	struct timeval timeout = { 0, 0 };
 
-	if (device->streaming)
+	if (device->stop_requested)
 	{
-		device->stop_requested = true;
+		device->stop_requested = false;
+		device->streaming = false;
 		cancel_transfers(device);
 
 		pthread_mutex_lock(&device->consumer_mp);
@@ -530,9 +531,6 @@ static int kill_io_threads(airspy_device_t* device)
 		pthread_join(device->consumer_thread, NULL);
 
 		libusb_handle_events_timeout_completed(device->usb_context, &timeout, NULL);
-
-		device->stop_requested = false;
-		device->streaming = false;
 	}
 
 	return AIRSPY_SUCCESS;
@@ -1212,14 +1210,16 @@ int airspy_list_devices(uint64_t *serials, int count)
 	int ADDCALL airspy_stop_rx(airspy_device_t* device)
 	{
 		int result1, result2;
-		result1 = kill_io_threads(device);
 
-		result2 = airspy_set_receiver_mode(device, RECEIVER_MODE_OFF);
-		if (result2 != AIRSPY_SUCCESS)
+		device->stop_requested = true;
+		result1 = airspy_set_receiver_mode(device, RECEIVER_MODE_OFF);
+		result2 = kill_io_threads(device);
+
+		if (result1 != AIRSPY_SUCCESS)
 		{
-			return result2;
+			return result1;
 		}
-		return result1;
+		return result2;
 	}
 
 	int ADDCALL airspy_si5351c_read(airspy_device_t* device, uint8_t register_number, uint8_t* value)
diff --git a/libairspy/src/airspy.h b/libairspy/src/airspy.h
index 489962a..573298b 100644
--- a/libairspy/src/airspy.h
+++ b/libairspy/src/airspy.h
@@ -28,10 +28,10 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSI
 #include <stdint.h>
 #include "airspy_commands.h"
 
-#define AIRSPY_VERSION "1.0.11"
+#define AIRSPY_VERSION "1.0.12"
 #define AIRSPY_VER_MAJOR 1
 #define AIRSPY_VER_MINOR 0
-#define AIRSPY_VER_REVISION 11
+#define AIRSPY_VER_REVISION 12
 
 #ifdef _WIN32
 	 #define ADD_EXPORTS
-- 
2.47.3