Feature/no active idle 2

This replaces #502 and #515.

The only change is to the the master now, which minimizes wakeups by choosing the right timeout. Many thanks to @Glandos for the original patches and to @davisp for the review.