2 * Migration Threads info
4 * Copyright (c) 2022 HUAWEI TECHNOLOGIES CO., LTD.
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);
30 thread
->thread_id
= thread_id
;
32 WITH_QEMU_LOCK_GUARD(&migration_threads_lock
) {
33 QLIST_INSERT_HEAD(&migration_threads
, thread
, node
);
39 void migration_threads_remove(MigrationThread
*thread
)
41 QEMU_LOCK_GUARD(&migration_threads_lock
);
43 QLIST_REMOVE(thread
, node
);
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
);