Use a pipe to signal pending work for the iothread.
Signed-off-by: Marcelo Tosatti <address@hidden>
Index: trunk/qemu-common.h
===================================================================
--- trunk.orig/qemu-common.h
+++ trunk/qemu-common.h
@@ -186,6 +186,8 @@ int cpu_load(QEMUFile *f, void *opaque,
/* Force QEMU to stop what it's doing and service IO */
void qemu_service_io(void);
+void main_loop_break(void);
+
/* Force QEMU to process pending events */
void qemu_notify_event(void);
Index: trunk/vl.c
===================================================================
--- trunk.orig/vl.c
+++ trunk/vl.c
@@ -276,6 +276,8 @@ static QEMUTimer *nographic_timer;
uint8_t qemu_uuid[16];
+static int io_thread_fd = -1;
+
/***********************************************************/
/* x86 ISA bus support */
@@ -3632,6 +3634,55 @@ void qemu_notify_event(void)
}
}
+void main_loop_break(void)
+{
+ uint64_t value = 1;
+ char buffer[8];
+ size_t offset = 0;
+
+ if (io_thread_fd == -1)
+ return;
+
+ memcpy(buffer, &value, sizeof(value));
+
+ while (offset < 8) {
+ ssize_t len;
+
+ len = write(io_thread_fd, buffer + offset, 8 - offset);
+ if (len == -1 && errno == EINTR)
+ continue;
+
+ if (len <= 0)
+ break;
+
+ offset += len;
+ }
+
+ if (offset != 8)
+ fprintf(stderr, "failed to notify io thread\n");
+}