threadinfo.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 "threadinfo.h"
  13. static QLIST_HEAD(, MigrationThread) migration_threads;
  14. MigrationThread *MigrationThreadAdd(const char *name, int thread_id)
  15. {
  16. MigrationThread *thread = g_new0(MigrationThread, 1);
  17. thread->name = name;
  18. thread->thread_id = thread_id;
  19. QLIST_INSERT_HEAD(&migration_threads, thread, node);
  20. return thread;
  21. }
  22. void MigrationThreadDel(MigrationThread *thread)
  23. {
  24. if (thread) {
  25. QLIST_REMOVE(thread, node);
  26. g_free(thread);
  27. }
  28. }
  29. MigrationThreadInfoList *qmp_query_migrationthreads(Error **errp)
  30. {
  31. MigrationThreadInfoList *head = NULL;
  32. MigrationThreadInfoList **tail = &head;
  33. MigrationThread *thread = NULL;
  34. QLIST_FOREACH(thread, &migration_threads, node) {
  35. MigrationThreadInfo *info = g_new0(MigrationThreadInfo, 1);
  36. info->name = g_strdup(thread->name);
  37. info->thread_id = thread->thread_id;
  38. QAPI_LIST_APPEND(tail, info);
  39. }
  40. return head;
  41. }