session.c: Remove all remaining sources on sr_session_stop

Some sources may not be necessarily associated with a device. The best example
is the anykey pollfd from sigrok-cli. sr_session_stop only removes sources
associated with hardware devices via dev_acquisition_stop. Sources such as
anykey are not removed, and thus session->num_sources will not get to 0. As a
result, we may get into situations where the event loop enters an infinite
state.

To prevent this, all we have to do is remove any active sources that are still
present after dev_acquisition_stop has been called for all devices.

This fixes bug 14.
This commit is contained in:
Alexandru Gagniuc 2012-12-19 04:15:18 -06:00 committed by Bert Vermeulen
parent dc890b8f9f
commit f1f7e62d6d
1 changed files with 9 additions and 0 deletions

View File

@ -362,6 +362,15 @@ SR_API int sr_session_stop(void)
}
}
/*
* Some sources may not be necessarily associated with a device.
* Those sources may still be present even after stopping all devices.
* We need to make sure all sources are removed, or we risk running the
* session in an infinite loop.
*/
while (session->num_sources)
sr_session_source_remove(session->sources[0].poll_object);
return SR_OK;
}