]> git.proxmox.com Git - mirror_qemu.git/blame - migration/threadinfo.c
Merge tag 'pull-trivial-patches' of https://gitlab.com/mjt0k/qemu into staging
[mirror_qemu.git] / migration / threadinfo.c
CommitLineData
67132620
JJ
1/*
2 * Migration Threads info
3 *
4 * Copyright (c) 2022 HUAWEI TECHNOLOGIES CO., LTD.
5 *
6 * Authors:
7 * Jiang Jiacheng <jiangjiacheng@huawei.com>
8 *
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.
11 */
12
01ec0f3a
FR
13#include "qemu/osdep.h"
14#include "qemu/queue.h"
15#include "qemu/lockable.h"
67132620
JJ
16#include "threadinfo.h"
17
01ec0f3a 18QemuMutex migration_threads_lock;
67132620
JJ
19static QLIST_HEAD(, MigrationThread) migration_threads;
20
01ec0f3a
FR
21static void __attribute__((constructor)) migration_threads_init(void)
22{
23 qemu_mutex_init(&migration_threads_lock);
24}
25
788fa680 26MigrationThread *migration_threads_add(const char *name, int thread_id)
67132620
JJ
27{
28 MigrationThread *thread = g_new0(MigrationThread, 1);
29 thread->name = name;
30 thread->thread_id = thread_id;
31
01ec0f3a
FR
32 WITH_QEMU_LOCK_GUARD(&migration_threads_lock) {
33 QLIST_INSERT_HEAD(&migration_threads, thread, node);
34 }
67132620
JJ
35
36 return thread;
37}
38
788fa680 39void migration_threads_remove(MigrationThread *thread)
67132620 40{
01ec0f3a 41 QEMU_LOCK_GUARD(&migration_threads_lock);
67132620
JJ
42 if (thread) {
43 QLIST_REMOVE(thread, node);
44 g_free(thread);
45 }
46}
47
48MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp)
49{
50 MigrationThreadInfoList *head = NULL;
51 MigrationThreadInfoList **tail = &head;
52 MigrationThread *thread = NULL;
53
01ec0f3a 54 QEMU_LOCK_GUARD(&migration_threads_lock);
67132620
JJ
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;
59
60 QAPI_LIST_APPEND(tail, info);
61 }
62
63 return head;
64}