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
|
From 1a50792c821f4fada60ffebc810c84e4f0c9f941 Mon Sep 17 00:00:00 2001
From: Johan Hedin <johan.o.hedin@gmail.com>
Date: Thu, 11 Jan 2024 13:27:17 +0100
Subject: [PATCH 21/29] Dedicated variables to guard pthread_join()
Use dedicated variables instead of relying on the value of the thread
id.
---
libairspy/src/airspy.c | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/libairspy/src/airspy.c b/libairspy/src/airspy.c
index 7766a18..a2caf38 100644
--- a/libairspy/src/airspy.c
+++ b/libairspy/src/airspy.c
@@ -86,6 +86,8 @@ typedef struct airspy_device
volatile bool stop_requested;
pthread_t transfer_thread;
pthread_t consumer_thread;
+ bool transfer_thread_running;
+ bool consumer_thread_running;
pthread_cond_t consumer_cv;
pthread_mutex_t consumer_mp;
uint32_t supported_samplerate_count;
@@ -529,13 +531,13 @@ static int kill_io_threads(airspy_device_t* device)
pthread_cond_signal(&device->consumer_cv);
pthread_mutex_unlock(&device->consumer_mp);
- if (device->transfer_thread != 0) {
+ if (device->transfer_thread_running) {
pthread_join(device->transfer_thread, NULL);
- device->transfer_thread = 0;
+ device->transfer_thread_running = false;
}
- if (device->consumer_thread != 0) {
+ if (device->consumer_thread_running) {
pthread_join(device->consumer_thread, NULL);
- device->consumer_thread = 0;
+ device->consumer_thread_running = false;
}
libusb_handle_events_timeout_completed(device->usb_context, &timeout, NULL);
@@ -572,12 +574,14 @@ static int create_io_threads(airspy_device_t* device, airspy_sample_block_cb_fn
{
return AIRSPY_ERROR_THREAD;
}
+ device->consumer_thread_running = true;
result = pthread_create(&device->transfer_thread, &attr, transfer_threadproc, device);
if (result != 0)
{
return AIRSPY_ERROR_THREAD;
}
+ device->transfer_thread_running = true;
pthread_attr_destroy(&attr);
}
--
2.47.3
|