aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2018-10-06 08:41:15 -0700
committerBrent Stapleton <bstapleton@g.hmc.edu>2018-11-14 18:01:51 -0800
commitd901b1e70801bae4974b2403b9762be368774e9b (patch)
tree838772aabd32ab2027fefd930a9b76052168436f
parentb3d2fff210f71d6cf1f54da67f7331d578a16169 (diff)
downloaduhd-d901b1e70801bae4974b2403b9762be368774e9b.tar.gz
uhd-d901b1e70801bae4974b2403b9762be368774e9b.tar.bz2
uhd-d901b1e70801bae4974b2403b9762be368774e9b.zip
python: tighten the scope of releasing the GIL
Only release the GIL for the calls to send() and recv(), instead of the entire wrapper functions.
-rw-r--r--host/lib/stream_python.hpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/host/lib/stream_python.hpp b/host/lib/stream_python.hpp
index 33ce50dc0..e07d120f1 100644
--- a/host/lib/stream_python.hpp
+++ b/host/lib/stream_python.hpp
@@ -18,9 +18,6 @@ static size_t wrap_recv(uhd::rx_streamer *rx_stream,
bp::object &metadata,
const double timeout = 0.1)
{
- // Release the GIL
- scoped_gil_release gil_release;
-
// Extract the metadata
bp::extract<uhd::rx_metadata_t&> get_metadata(metadata);
if (not get_metadata.check())
@@ -71,13 +68,17 @@ static size_t wrap_recv(uhd::rx_streamer *rx_stream,
nsamps_per_buff = PyArray_SIZE(array_type_obj);
}
- // Call the real recv()
- const size_t result = rx_stream->recv(
- channel_storage,
- nsamps_per_buff,
- get_metadata(),
- timeout
- );
+ // Release the GIL only for the recv() call
+ const size_t result = [&]() {
+ scoped_gil_release gil_release;
+ // Call the real recv()
+ return rx_stream->recv(
+ channel_storage,
+ nsamps_per_buff,
+ get_metadata(),
+ timeout
+ );
+ }();
// Manually decrement the ref count
Py_DECREF(array_obj);
@@ -90,9 +91,6 @@ static size_t wrap_send(uhd::tx_streamer *tx_stream,
bp::object &metadata,
const double timeout = 0.1)
{
- // Release the GIL
- scoped_gil_release gil_release;
-
// Extract the metadata
bp::extract<uhd::tx_metadata_t&> get_metadata(metadata);
// TODO: throw an error here?
@@ -140,13 +138,17 @@ static size_t wrap_send(uhd::tx_streamer *tx_stream,
// Get data buffer and size of the array
size_t nsamps_per_buff = (dims > 1) ? (size_t) shape[1] : PyArray_SIZE(array_type_obj);
- // Call the real recv()
- const size_t result = tx_stream->send(
- channel_storage,
- nsamps_per_buff,
- get_metadata(),
- timeout
- );
+ // Release the GIL only for the send() call
+ const size_t result = [&]() {
+ scoped_gil_release gil_release;
+ // Call the real send()
+ return tx_stream->send(
+ channel_storage,
+ nsamps_per_buff,
+ get_metadata(),
+ timeout
+ );
+ }();
// Manually decrement the ref count
Py_DECREF(array_obj);