Protect uhd_tx_streamer_send() by a mutex inside rf driver

master
Ismael Gomez 7 years ago
parent f8655f3260
commit a87e7b3e43

@ -61,6 +61,8 @@ typedef struct {
bool async_thread_running; bool async_thread_running;
pthread_t async_thread; pthread_t async_thread;
pthread_mutex_t tx_mutex;
} rf_uhd_handler_t; } rf_uhd_handler_t;
void suppress_handler(const char *x) void suppress_handler(const char *x)
@ -374,6 +376,8 @@ int rf_uhd_open_multi(char *args, void **h, uint32_t nof_channels)
} }
handler->devname = NULL; handler->devname = NULL;
pthread_mutex_init(&handler->tx_mutex, NULL);
// Initialize handler // Initialize handler
handler->uhd_error_handler = NULL; handler->uhd_error_handler = NULL;
@ -819,9 +823,13 @@ int rf_uhd_send_timed_multi(void *h,
bool has_time_spec, bool has_time_spec,
bool blocking, bool blocking,
bool is_start_of_burst, bool is_start_of_burst,
bool is_end_of_burst) { bool is_end_of_burst)
{
rf_uhd_handler_t* handler = (rf_uhd_handler_t*) h; rf_uhd_handler_t* handler = (rf_uhd_handler_t*) h;
pthread_mutex_lock(&handler->tx_mutex);
int ret = -1;
/* Resets the USRP time FIXME: this might cause problems for burst transmissions */ /* Resets the USRP time FIXME: this might cause problems for burst transmissions */
if (!has_time_spec && is_start_of_burst && handler->nof_tx_channels > 1) { if (!has_time_spec && is_start_of_burst && handler->nof_tx_channels > 1) {
uhd_usrp_set_time_now(handler->usrp, 0, 0, 0); uhd_usrp_set_time_now(handler->usrp, 0, 0, 0);
@ -866,15 +874,18 @@ int rf_uhd_send_timed_multi(void *h,
tx_samples, &handler->tx_md, 3.0, &txd_samples); tx_samples, &handler->tx_md, 3.0, &txd_samples);
if (error) { if (error) {
fprintf(stderr, "Error sending to UHD: %d\n", error); fprintf(stderr, "Error sending to UHD: %d\n", error);
return -1; goto unlock;
} }
// Increase time spec // Increase time spec
uhd_tx_metadata_add_time_spec(&handler->tx_md, txd_samples/handler->tx_rate); uhd_tx_metadata_add_time_spec(&handler->tx_md, txd_samples/handler->tx_rate);
n += txd_samples; n += txd_samples;
trials++; trials++;
} while (n < nsamples && trials < 100); } while (n < nsamples && trials < 100);
return nsamples;
ret = nsamples;
} else { } else {
const void *buffs_ptr[4]; const void *buffs_ptr[4];
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
buffs_ptr[i] = data[i]; buffs_ptr[i] = data[i];
@ -885,9 +896,14 @@ int rf_uhd_send_timed_multi(void *h,
uhd_error error = uhd_tx_streamer_send(handler->tx_stream, buffs_ptr, nsamples, &handler->tx_md, 3.0, &txd_samples); uhd_error error = uhd_tx_streamer_send(handler->tx_stream, buffs_ptr, nsamples, &handler->tx_md, 3.0, &txd_samples);
if (error) { if (error) {
fprintf(stderr, "Error sending to UHD: %d\n", error); fprintf(stderr, "Error sending to UHD: %d\n", error);
return -1; goto unlock;
} }
return txd_samples;
ret = txd_samples;
} }
unlock:
pthread_mutex_unlock(&handler->tx_mutex);
return ret;
} }

Loading…
Cancel
Save