static void
ply_event_loop_handle_timeouts (ply_event_loop_t *loop)
{
+ ply_list_t *watches_to_dispatch;
ply_list_node_t *node;
double now;
now = ply_get_timestamp ();
node = ply_list_get_first_node (loop->timeout_watches);
+
+ watches_to_dispatch = ply_list_new ();
loop->wakeup_time = PLY_EVENT_LOOP_NO_TIMED_WAKEUP;
while (node != NULL)
{
if (watch->timeout <= now)
{
assert (watch->handler != NULL);
- watch->handler (watch->user_data, loop);
- free (watch);
+ ply_list_append_data (watches_to_dispatch, watch);
ply_list_remove_node (loop->timeout_watches, node);
}
else {
node = next_node;
}
+ node = ply_list_get_first_node (watches_to_dispatch);
+ while (node != NULL)
+ {
+ ply_list_node_t *next_node;
+ ply_event_loop_timeout_watch_t *watch;
+
+ watch = (ply_event_loop_timeout_watch_t *) ply_list_node_get_data (node);
+ next_node = ply_list_get_next_node (loop->timeout_watches, node);
+
+ watch->handler (watch->user_data, loop);
+ free (watch);
+
+ node = next_node;
+ }
+
+ ply_list_free (watches_to_dispatch);
+
}
static void