GPIO events and threads


I would like to have a thread read the state of an input pin while also having an event handler for it. The reason for this is that I am exposing an interface to an external app which needs to be able to both ask for the state of a pin and receive information about pin state changes. However, since my thread is busy waiting for input from the external app on a socket I cannot have the event handler execute in the thread context. But I cannot have the GPIO service connected to both the main thread and my connection thread at the same time.
Is there any way around this which does not encompass making some low level messaging (Low-level Messaging API - Legato Docs) between the connection thread and the main thread?

For all other API’s I have currently in use I can have the event handler in the main thread context which then can send the event information on all open sockets. But this doesn’t work for GPIO.

Yes I have. But sadly we are about to receive hardware today so I’m a little late for asking for changes in HW.
I have tried to make another thread for GPIO read and then use an API for communicating between the two threads, but I haven’t been able to make this work. Can’t even make the helloIpc example work if I modify it to be two components within the same application. I have a thread on that here too.

Actually, you should be able to achieve this once the API IPC issues are overcome.

Layered Publish-Subscribe Handlers could be useful for notifying clients of state changes, too.

I’ll take a look at your other thread.

It is exactly something like that I will build up if I can get the API stuff to work.

I solved this by ditching the legato gpio api and is instead using the sysfs implementation of the gpio driver. This I can safely do from multiple threads.