Normally, we want to wait for the stream to be running before
submitting a buffer. However, BLADERF_STREAM_SHUTDOWN is a special
case; we want to always submit this immediately so that we can
end a stream, even if it's not currently running.
This commit fixes#244.
Erroneous behavior has been observed with GRC flowgraphs, where stream
buffers are submitted before the underlying async stream is running.
Although I have not been able to replicate this, this patch should
ensure that a buffer submission is delayed until after the async
stream has been initialized and is starting to run.
To support cases where callbacks would need to block (which they can't),
the async stream implementation has been modified to support
bladerf_submit_stream_buffer(), which allows buffers to be submitted for
transfer outside of the callback functions.
There are some caveats to using this; the documentation has been updated
to note where care should be taken with lock acquisition.
Per the libusb documentation, the libusb async callbacks must be
executed atomically.
In half-duplex cases where one thread is sitting in a bladerf_stream()
call, this was a problem. However, in full-duplex cases, we can have
two threads, each calling a libusb handle_events fn, enter the callback
for a single module. This would result in:
- Buffers being passed to user callbacks in the wrong order
- Stream state and error conditions being corrupted