brian-armstrong / gpio

Go library to do GPIO on systems with /sys/class/gpio (sysfs)
BSD 3-Clause "New" or "Revised" License
140 stars 50 forks source link

De-jankify select() call #4

Open brian-armstrong opened 6 years ago

brian-armstrong commented 6 years ago

The merging of posix-style select() call with Go seems pretty jank, at least in this implementation. The select() has a 1-second timeout, so that if there are no pins changing, it takes up to a second to add and remove new pins to the watcher https://github.com/brian-armstrong/gpio/blob/master/watcher.go#L112 and https://github.com/brian-armstrong/gpio/blob/master/watcher.go#L193

We should investigate if it's possible to remove these in some way without impacting CPU.

One possible option, though sort of gross, would be to open a file in /tmp (or a socket) and have our select() call include it in its readfds. Then a goroutine could write to this file descriptor in order to wake up the select() caller, which could then do maintenance like adding/removing pins or closing. If we did this, we could possibly remove the 1-second timeout entirely, allowing us to sleep more while having very good latency for these sorts of operations.

temoto commented 5 years ago

@brian-armstrong poll syscall could fix timeout granularity problem.

Thanks for (maybe best to date?) GPIO library with edge event support.