pasis/libcouplet — pull request #11 by horazont (2013-04-21 11:13:44+00:00)
Title: Fix scheduler problem, which leads to infinite looping

This patch fixes a bug which occured under the following preconditions:

1. Several timed event handlers are registered and timed close enough that multiple of them get executed in one ``handler_fire_timed()`` run.

2. The timed event assigned to *tail* (the one which is the last in the queue at the point of ``handler_fire_timed()`` getting called) will return ``0``, so that it gets deleted from the list.

3. Another event handler executed in the same run returns 1.

In that case, ``handler_fire_timed`` would not return, because the comparision of the current item in the list with the item referenced in ``tail`` would never become true; Instead, ``handler_fire_timed`` would loop over and over through itself.

The proposed fix uses a temporary list to store the timed events which are to be readded into the queue and does not reinsert them
immediately, to be able to properly detect the end of the original
queue.