thread_manager.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _THREAD_MANAGER_H
  6. #define _THREAD_MANAGER_H
  7. #include "bh_common.h"
  8. #include "bh_log.h"
  9. #include "wasm_export.h"
  10. #include "../interpreter/wasm.h"
  11. #include "../common/wasm_runtime_common.h"
  12. #ifdef __cplusplus
  13. extern "C" {
  14. #endif
  15. typedef struct WASMCluster
  16. {
  17. struct WASMCluster *next;
  18. korp_mutex lock;
  19. bh_list exec_env_list;
  20. /* The aux stack of a module with shared memory will be
  21. divided into several segments. This array store the
  22. stack top of different segments */
  23. uint32 *stack_tops;
  24. /* Size of every stack segment */
  25. uint32 stack_size;
  26. /* Record which segments are occupied */
  27. bool *stack_segment_occupied;
  28. } WASMCluster;
  29. void wasm_cluster_set_max_thread_num(uint32 num);
  30. bool
  31. thread_manager_init();
  32. void
  33. thread_manager_destroy();
  34. /* Create cluster */
  35. WASMCluster *
  36. wasm_cluster_create(WASMExecEnv *exec_env);
  37. /* Destroy cluster */
  38. void
  39. wasm_cluster_destroy(WASMCluster *cluster);
  40. /* Get the cluster of the current exec_env */
  41. WASMCluster*
  42. wasm_exec_env_get_cluster(WASMExecEnv *exec_env);
  43. int32
  44. wasm_cluster_create_thread(WASMExecEnv *exec_env,
  45. wasm_module_inst_t module_inst,
  46. void* (*thread_routine)(void *),
  47. void *arg);
  48. int32
  49. wasm_cluster_join_thread(WASMExecEnv *exec_env, void **ret_val);
  50. int32
  51. wasm_cluster_detach_thread(WASMExecEnv *exec_env);
  52. int32
  53. wasm_cluster_cancel_thread(WASMExecEnv *exec_env);
  54. void
  55. wasm_cluster_exit_thread(WASMExecEnv *exec_env, void *retval);
  56. bool
  57. wasm_cluster_register_destroy_callback(void (*callback)(WASMCluster *));
  58. void
  59. wasm_cluster_cancel_all_callbacks();
  60. void
  61. wasm_cluster_suspend_all(WASMCluster *cluster);
  62. void
  63. wasm_cluster_suspend_all_except_self(WASMCluster *cluster,
  64. WASMExecEnv *exec_env);
  65. void
  66. wasm_cluster_suspend_thread(WASMExecEnv *exec_env);
  67. void
  68. wasm_cluster_resume_thread(WASMExecEnv *exec_env);
  69. void
  70. wasm_cluster_resume_all(WASMCluster *cluster);
  71. void
  72. wasm_cluster_terminate_all(WASMCluster *cluster);
  73. void
  74. wasm_cluster_terminate_all_except_self(WASMCluster *cluster,
  75. WASMExecEnv *exec_env);
  76. bool
  77. wasm_cluster_add_exec_env(WASMCluster *cluster, WASMExecEnv *exec_env);
  78. bool
  79. wasm_cluster_del_exec_env(WASMCluster *cluster, WASMExecEnv *exec_env);
  80. WASMExecEnv *
  81. wasm_clusters_search_exec_env(WASMModuleInstanceCommon *module_inst);
  82. void
  83. wasm_cluster_spread_exception(WASMExecEnv *exec_env);
  84. WASMExecEnv *
  85. wasm_cluster_spawn_exec_env(WASMExecEnv *exec_env);
  86. void
  87. wasm_cluster_destroy_spawned_exec_env(WASMExecEnv *exec_env);
  88. #ifdef __cplusplus
  89. }
  90. #endif
  91. #endif /* end of _THREAD_MANAGER_H */