Re: [Discuss-gnuradio] Deleting a block in C++

2012-06-13 Thread Johnathan Corgan
On Fri, Jun 8, 2012 at 11:03 AM, Alexandru Csete  wrote:


> Is there a smart way to delete a GNU Radio block in C++?
> Until now I have been using the shared_ptr().reset() method but it
> seems to me that it will only call the destructor if the parent
> top_block has not been run.
>

"Don't do that."

The reference count in the smart pointer is designed to increment and
decrement according to usage and scoping.  Calling reset() is reserved for
very special situations.

The reason the destructor doesn't get called is that the flowgraph
structure itself (created by the call to connect() ) internally stores a
copy of the pointer; thus, the reference count never goes to zero.
Resetting it manually is an invitation to a future segfault.


> This gives me problems when I try to delete and recreate a hardware
> input block (e.g. gr-audio input) where the new device can be the same
> as the old one, in which case it will report "device busy".
>
> [...]

>
> Perhaps these hardware input blocks are coded incorrectly and should
> close the device in their stop() method? Or is there something else we
> can do?
>


You've pegged the real issue.  It's probably a good idea to make start()
and stop() do the actual hardware acquisition and release.  I expect this
is not trivial, but would be a great improvement in how those blocks can be
used.

Johnathan
___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio


[Discuss-gnuradio] Deleting a block in C++

2012-06-08 Thread Alexandru Csete
Greetings,

Is there a smart way to delete a GNU Radio block in C++?
Until now I have been using the shared_ptr().reset() method but it
seems to me that it will only call the destructor if the parent
top_block has not been run.

This gives me problems when I try to delete and recreate a hardware
input block (e.g. gr-audio input) where the new device can be the same
as the old one, in which case it will report "device busy".
The specific code in question is here:
https://github.com/csete/gqrx/blob/afd02e241f0569e485ecbb1c312599ba60c5431c/applications/gqrx/receiver.cpp#L112

It makes no difference if I stop() the top block before attempting the reset().


Perhaps these hardware input blocks are coded incorrectly and should
close the device in their stop() method? Or is there something else we
can do?

Thanks in advance

Alex

___
Discuss-gnuradio mailing list
Discuss-gnuradio@gnu.org
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio