discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] about the work function and memory


From: Johnathan Corgan
Subject: Re: [Discuss-gnuradio] about the work function and memory
Date: Fri, 26 Feb 2010 14:39:13 -0800

On Fri, Feb 26, 2010 at 14:05, Josh Blum <address@hidden> wrote:

> Here is a typical work function:
> int work(int noutput_items,
>                       gr_vector_const_void_star &input_items,
>                       gr_vector_void_star &output_items)
>
> output_items seems to be a pointer to a pointer into some pre-allocated
> memory. What is stopping me from managing my own memory, pointing the output
> items pointer into my memory, and returning an arbitrary noutput_items?
>
> Is it possible? What are the limitations?

Short answer: no.

Longer answer:

The memory pointed to by the output_items vector is a shared buffer
created by the GNU Radio runtime, which implements a thread-safe,
single writer, multi-reader shared ring buffer.  The readers in this
case are the downstream blocks inputs that are set up when by calling
'connect'.  See gr_buffer and related classes in the core runtime
directory.  When your work function returns the number of items
produced, the runtime adjusts the buffer pointers and "knows" to
signal other connected block threads that input is available.
Likewise, when a work function calls consume, it is telling the
runtime to adjust the input reader pointer, and when all downstream
blocks have moved their reader pointers far enough, the runtime
"knows" to signal upstream block threads that their work function can
be called again.  It's all a highly optimized dance.

Johnathan




reply via email to

[Prev in Thread] Current Thread [Next in Thread]