Blocking read

Hello all.

So far I wrote a kernel driver that can read pwm encoded signal. I’d like to pass the data to the userspace now and this is what I’m thinking:

User app creates several threads, one of which reads a device file in a loop. I want the read function to efficiently block, putting the thread to sleep until data is available. There will be other devices as well, some serial, thus other threads, but I’d like to use the same mechanism.

How should I go about implementing this?

Thanks and BR

Miro

Hi Miro,

Hello all.

So far I wrote a kernel driver that can read pwm encoded signal. I’d like to pass the data to the userspace now and this is what I’m thinking:

User app creates several threads, one of which reads a device file in a loop. I want the read function to efficiently block, putting the thread to sleep until data is available. There will be other devices as well, some serial, thus other threads, but I’d like to use the same mechanism.

How should I go about implementing this?

Here’s a multi-threaded serial port example:
https://github.com/dhylands/projects/tree/master/host/sertest

and the single-threaded version (which uses select)
https://github.com/dhylands/projects/tree/master/host/sertest-select

This is a kernel driver I wrote quite a while ago for reading gpio events. It has support for blocking and non-blocking reads (see the gpio_event_read function) and select (see gpio_event_poll)
https://github.com/dhylands/projects/tree/master/linux/gpio-event/module

I have to admit I haven’t tried compiling this on a 3.0 kernel, but even if it doesn’t compile, the concepts should all still be applicable.

Feel free to ask questions.