aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorMarc-André Lureau <marcandre.lureau@redhat.com>2019-01-17 15:43:55 +0400
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2019-02-07 15:49:08 +0200
commit1ab67b98cdd78b94ce818a7d0a964e3e4d7a4538 (patch)
tree6170bef3ba22ffbe442ccd9e0336bbbbc0e49297 /util
parent625a526b3298ce593983923b4d10fa582555f26d (diff)
slirp: replace global polling with per-instance & notifier
Remove hard-coded dependency on slirp in main-loop, and use a "poll" notifier instead. The notifier is registered per slirp instance. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Signed-off-by: Samuel Thibault <samuel.thibault@ens-lyon.org>
Diffstat (limited to 'util')
-rw-r--r--util/main-loop.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/util/main-loop.c b/util/main-loop.c
index 443cb4cfe8..d4a521caeb 100644
--- a/util/main-loop.c
+++ b/util/main-loop.c
@@ -469,25 +469,42 @@ static int os_host_main_loop_wait(int64_t timeout)
}
#endif
+static NotifierList main_loop_poll_notifiers =
+ NOTIFIER_LIST_INITIALIZER(main_loop_poll_notifiers);
+
+void main_loop_poll_add_notifier(Notifier *notify)
+{
+ notifier_list_add(&main_loop_poll_notifiers, notify);
+}
+
+void main_loop_poll_remove_notifier(Notifier *notify)
+{
+ notifier_remove(notify);
+}
+
void main_loop_wait(int nonblocking)
{
+ MainLoopPoll mlpoll = {
+ .state = MAIN_LOOP_POLL_FILL,
+ .timeout = UINT32_MAX,
+ .pollfds = gpollfds,
+ };
int ret;
- uint32_t timeout = UINT32_MAX;
int64_t timeout_ns;
if (nonblocking) {
- timeout = 0;
+ mlpoll.timeout = 0;
}
/* poll any events */
g_array_set_size(gpollfds, 0); /* reset for new iteration */
/* XXX: separate device handlers from system ones */
- slirp_pollfds_fill(gpollfds, &timeout);
+ notifier_list_notify(&main_loop_poll_notifiers, &mlpoll);
- if (timeout == UINT32_MAX) {
+ if (mlpoll.timeout == UINT32_MAX) {
timeout_ns = -1;
} else {
- timeout_ns = (uint64_t)timeout * (int64_t)(SCALE_MS);
+ timeout_ns = (uint64_t)mlpoll.timeout * (int64_t)(SCALE_MS);
}
timeout_ns = qemu_soonest_timeout(timeout_ns,
@@ -495,7 +512,8 @@ void main_loop_wait(int nonblocking)
&main_loop_tlg));
ret = os_host_main_loop_wait(timeout_ns);
- slirp_pollfds_poll(gpollfds, (ret < 0));
+ mlpoll.state = ret < 0 ? MAIN_LOOP_POLL_ERR : MAIN_LOOP_POLL_OK;
+ notifier_list_notify(&main_loop_poll_notifiers, &mlpoll);
/* CPU thread can infinitely wait for event after
missing the warp */