MultiFDMethods *ops;
} *multifd_send_state;
+struct {
+ MultiFDRecvParams *params;
+ /* number of created threads */
+ int count;
+ /* syncs main thread and channels */
+ QemuSemaphore sem_sync;
+ /* global number of generated multifd packets */
+ uint64_t packet_num;
+ int exiting;
+ /* multifd ops */
+ MultiFDMethods *ops;
+} *multifd_recv_state;
+
/* Multifd without compression */
/**
return qatomic_read(&multifd_send_state->exiting);
}
+static bool multifd_recv_should_exit(void)
+{
+ return qatomic_read(&multifd_recv_state->exiting);
+}
+
/*
* The migration thread can wait on either of the two semaphores. This
* function can be used to kick the main thread out of waiting on either of
return true;
}
-struct {
- MultiFDRecvParams *params;
- /* number of created threads */
- int count;
- /* syncs main thread and channels */
- QemuSemaphore sem_sync;
- /* global number of generated multifd packets */
- uint64_t packet_num;
- /* multifd ops */
- MultiFDMethods *ops;
-} *multifd_recv_state;
-
static void multifd_recv_terminate_threads(Error *err)
{
int i;
trace_multifd_recv_terminate_threads(err != NULL);
+ if (qatomic_xchg(&multifd_recv_state->exiting, 1)) {
+ return;
+ }
+
if (err) {
MigrationState *s = migrate_get_current();
migrate_set_error(s, err);
for (i = 0; i < migrate_multifd_channels(); i++) {
MultiFDRecvParams *p = &multifd_recv_state->params[i];
- qemu_mutex_lock(&p->mutex);
- p->quit = true;
/*
* We could arrive here for two reasons:
* - normal quit, i.e. everything went fine, just finished
if (p->c) {
qio_channel_shutdown(p->c, QIO_CHANNEL_SHUTDOWN_BOTH, NULL);
}
- qemu_mutex_unlock(&p->mutex);
}
}
while (true) {
uint32_t flags;
- if (p->quit) {
+ if (multifd_recv_should_exit()) {
break;
}
multifd_recv_state = g_malloc0(sizeof(*multifd_recv_state));
multifd_recv_state->params = g_new0(MultiFDRecvParams, thread_count);
qatomic_set(&multifd_recv_state->count, 0);
+ qatomic_set(&multifd_recv_state->exiting, 0);
qemu_sem_init(&multifd_recv_state->sem_sync, 0);
multifd_recv_state->ops = multifd_ops[migrate_multifd_compression()];
qemu_mutex_init(&p->mutex);
qemu_sem_init(&p->sem_sync, 0);
- p->quit = false;
p->id = i;
p->packet_len = sizeof(MultiFDPacket_t)
+ sizeof(uint64_t) * page_count;