beagleboard/am335x_pru_package — pull request #21 by fhunleth (2014-02-05 22:48:34+00:00)
Title: prussdrv: Remove pthreads dependency

This change removes the prussdrv_start_irqthread helper function and hence removes the only pthreads dependency in the am335x_pru_package. None of the examples use the function, so the removal of pthreads is propagated through the example Makefiles. While pthreads is almost certainly available on the Beaglebones that use this library, here are a few reasons why this change is a good one.

1. Seeing pthreads on the link line is a immediate warning sign that threading is in use, so it's reasonable to review the library to make sure that it plays well with application code. Since the am335x_pru_package doesn't really use threading internally at all, removing pthreads removes any doubt that a library call will do something unexpected with threads.
2. The API isn't threadsafe, since shared data is not protected by a mutex. It seems a little scary doing much work in the irqthread without careful thought.
3. While the irq_thread provides the looping structure to wait for PRU interrupts, it didn't have a way to pass messages to it. I.e, to exit the thread or to change a parameter for how the application handles the interrupts. I would imagine that many PRU use cases need some kind of message passing to their interrupt handling threads since the PRU provides some ongoing processing rather than a one-off. I addressed passing messages to my PRU interrupt handler by using select(2) and a message pipe, but I would have done it different if I were using Qt or STL. I think threading is better addressed by the application.
4. Removing the pthreads dependency lets the library be used with toolchains that don't include pthreads. As far as I know, this is only needed for custom uclibc builds, but it is conceivable that someone may build a very small Linux system that uses the PRU app_loader.

I'm curious if anyone actually uses irqthread, and if they do, whether it would bother them that much to move the pthread creation calls into their code.