[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Discuss-gnuradio] Shared resource for source and sink blocks
From: |
N. Benes |
Subject: |
Re: [Discuss-gnuradio] Shared resource for source and sink blocks |
Date: |
Fri, 26 Apr 2019 09:41:00 +0000 |
N. Benes:
> what is the accepted best practice to have a source and a sink block
> share a common resource?
> In my case, the shared resource is a thread that does I/O and both
> source/sink use it to interface to GNU Radio.
[snip]
> Is there a commonly accepted pattern to apply in this situation?
I had a look at the UHD/USRP source:
https://github.com/EttusResearch/uhd/tree/master/host/lib/
The usrp_block_impl in GNU Radio creates a new instance of
::uhd::usrp::multi_usrp which internally retrieves a device from a
static map, either creating a new device or re-using an already existing
one:
https://github.com/EttusResearch/uhd/blob/master/host/lib/device.cpp#L175
> device::sptr device::make(const device_addr_t &hint, device_filter_t filter,
> size_t which){
...
> //map device address hash to created devices
> static uhd::dict<size_t, boost::weak_ptr<device> > hash_to_device;
>
> //try to find an existing device
> if (hash_to_device.has_key(dev_hash) and not
> hash_to_device[dev_hash].expired()){
> return hash_to_device[dev_hash].lock();
> }
> else {
> // Add keys from the config files (note: the user-defined keys will
> // always be applied, see also get_usrp_args()
> // Then, create and register a new device.
> device::sptr dev = maker(prefs::get_usrp_args(dev_addr));
> hash_to_device[dev_hash] = dev;
> return dev;
> }
> }
So this seems to be a suitable pattern for my case.
Cheers,
nicolas