dump: Drop redundant check for empty dump
[qemu/armbru.git] / migration / threadinfo.c
blob262990dd75ae853fb6cfe1d27fd41a89680538d1
1 /*
2 * Migration Threads info
4 * Copyright (c) 2022 HUAWEI TECHNOLOGIES CO., LTD.
6 * Authors:
7 * Jiang Jiacheng <jiangjiacheng@huawei.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qemu/queue.h"
15 #include "qemu/lockable.h"
16 #include "threadinfo.h"
18 QemuMutex migration_threads_lock;
19 static QLIST_HEAD(, MigrationThread) migration_threads;
21 static void __attribute__((constructor)) migration_threads_init(void)
23 qemu_mutex_init(&migration_threads_lock);
26 MigrationThread *migration_threads_add(const char *name, int thread_id)
28 MigrationThread *thread = g_new0(MigrationThread, 1);
29 thread->name = name;
30 thread->thread_id = thread_id;
32 WITH_QEMU_LOCK_GUARD(&migration_threads_lock) {
33 QLIST_INSERT_HEAD(&migration_threads, thread, node);
36 return thread;
39 void migration_threads_remove(MigrationThread *thread)
41 QEMU_LOCK_GUARD(&migration_threads_lock);
42 if (thread) {
43 QLIST_REMOVE(thread, node);
44 g_free(thread);
48 MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp)
50 MigrationThreadInfoList *head = NULL;
51 MigrationThreadInfoList **tail = &head;
52 MigrationThread *thread = NULL;
54 QEMU_LOCK_GUARD(&migration_threads_lock);
55 QLIST_FOREACH(thread, &migration_threads, node) {
56 MigrationThreadInfo *info = g_new0(MigrationThreadInfo, 1);
57 info->name = g_strdup(thread->name);
58 info->thread_id = thread->thread_id;
60 QAPI_LIST_APPEND(tail, info);
63 return head;