Page 1 of 1

data-pipe between threads.

Posted: Thu Jan 01, 2015 3:06 pm
by rew
Hi,
I'm writing something with an ESP8266, so I occasionally get data from the other side. So far I simply dump it on the console, but on short notice, I will have to start doing something with it.

Is there a chibios way of passing "byte stream" oriented data between threads?

Re: data-pipe between threads.

Posted: Thu Jan 01, 2015 3:15 pm
by Giovanni
Hi,

You can use mailboxes for this.

Giovanni

Re: data-pipe between threads.

Posted: Thu Jan 01, 2015 3:35 pm
by rew
Ok. But if I then "post" data of just one byte, I'll have to allocate 4 times "spare" memory for the buffer, right?

I could improve on memory efficiency by implementing something similar with a "byte" datatype.

Re: data-pipe between threads.

Posted: Thu Jan 01, 2015 4:50 pm
by Giovanni
You may use I/O queues that are byte oriented but those are non-blocking on one side.

Giovanni

Re: data-pipe between threads.

Posted: Thu Jan 01, 2015 5:36 pm
by rew
Now he tells me, just when I have the message queue implementation working... :-)

Thanks! It seems that the IO queue would be a better fit. I currently just have a thread that reads a byte at a time from the ESP8266, and now, when appropriate it puts it on the message queue. But eventually, I'll move to that other kind of serial driver where my callback gets called each time a character comes in. Then, when appropriate, putting things into that IO queue would be ideal.

For now it works, and when I get performance or memory problems I know where I can shave off some bytes.. :-)

Re: data-pipe between threads.

Posted: Fri Aug 14, 2015 4:37 pm
by rew
Very similar problem. Currently working on the input thread is waiting for serial input, but should/would switch to USB input the next time it reads a character.

The input thread has a big call-stack. Duplicating it for both the USB-serial input and physical-serial input is not possible (chip is out of memory).

Waiting with a timeout would work acceptable I'd say. But the BaseSequentialStream does not support timeouts.

Then I found memory streams. I thought they would allow me to pass data from one process to the other, but looking at the implementation, memory is never reused. So if I declare my buffer to be 100 bytes, I can transfer 100 bytes and never more. Correct?

What's the use of such a stream? I appreciate the use case: put data in flash, and process it with a function that is used to BaseSequentialStream as input.

Re: data-pipe between threads.

Posted: Fri Aug 14, 2015 5:05 pm
by Giovanni
Hi,

MemoryStreams are the equivalent of Java string buffers, those are for handling a memory buffer using a stream interface.

Passing data among threads is done using mailboxes or messages.

Giovanni