threadinfo.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. #include "qemu/osdep.h"
  13. #include "qemu/queue.h"
  14. #include "qemu/lockable.h"
  15. #include "threadinfo.h"
  16. QemuMutex migration_threads_lock;
  17. static QLIST_HEAD(, MigrationThread) migration_threads;
  18. static void __attribute__((constructor)) migration_threads_init(void)
  19. {
  20. qemu_mutex_init(&migration_threads_lock);
  21. }
  22. MigrationThread *migration_threads_add(const char *name, int thread_id)
  23. {
  24. MigrationThread *thread = g_new0(MigrationThread, 1);
  25. thread->name = name;
  26. thread->thread_id = thread_id;
  27. WITH_QEMU_LOCK_GUARD(&migration_threads_lock) {
  28. QLIST_INSERT_HEAD(&migration_threads, thread, node);
  29. }
  30. return thread;
  31. }
  32. void migration_threads_remove(MigrationThread *thread)
  33. {
  34. QEMU_LOCK_GUARD(&migration_threads_lock);
  35. if (thread) {
  36. QLIST_REMOVE(thread, node);
  37. g_free(thread);
  38. }
  39. }
  40. MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp)
  41. {
  42. MigrationThreadInfoList *head = NULL;
  43. MigrationThreadInfoList **tail = &head;
  44. MigrationThread *thread = NULL;
  45. QEMU_LOCK_GUARD(&migration_threads_lock);
  46. QLIST_FOREACH(thread, &migration_threads, node) {
  47. MigrationThreadInfo *info = g_new0(MigrationThreadInfo, 1);
  48. info->name = g_strdup(thread->name);
  49. info->thread_id = thread->thread_id;
  50. QAPI_LIST_APPEND(tail, info);
  51. }
  52. return head;
  53. }