Add "volatile" to two fields of rtlsdr_dev

librtlsdr uses two fileds of struct rtlsdr_dev to communicate
between threads. On hardware with weak memory model it is not
guaranteed that it will work, as C memory model guarantees
nothing for simple variables.

 Using C11 atomics seems to be overkill here, but async_status
and async_cancel better be marked as "volatile".
development
Lev Serebryakov 2017-02-07 18:35:35 +03:00 committed by hayati ayguen
parent b09c635885
commit 037d192d76
1 changed files with 3 additions and 3 deletions

View File

@ -191,8 +191,8 @@ struct rtlsdr_dev {
unsigned char **xfer_buf;
rtlsdr_read_async_cb_t cb;
void *cb_ctx;
enum rtlsdr_async_status async_status;
int async_cancel;
volatile enum rtlsdr_async_status async_status;
volatile int async_cancel;
int use_zerocopy;
/* rtl demod context */
uint32_t rate; /* Hz */
@ -3539,7 +3539,7 @@ int rtlsdr_read_async(rtlsdr_dev_t *dev, rtlsdr_read_async_cb_t cb, void *ctx,
while (RTLSDR_INACTIVE != dev->async_status) {
r = libusb_handle_events_timeout_completed(dev->ctx, &tv,
&dev->async_cancel);
(int *)&dev->async_cancel);
if (r < 0) {
/*fprintf(stderr, "handle_events returned: %d\n", r);*/
if (r == LIBUSB_ERROR_INTERRUPTED) /* stray signal */