wasm_shared_memory.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2019 Intel Corporation. All rights reserved.
  3. * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. */
  5. #ifndef _WASM_SHARED_MEMORY_H
  6. #define _WASM_SHARED_MEMORY_H
  7. #include "bh_common.h"
  8. #if WASM_ENABLE_INTERP != 0
  9. #include "wasm_runtime.h"
  10. #endif
  11. #if WASM_ENABLE_AOT != 0
  12. #include "aot_runtime.h"
  13. #endif
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. typedef struct WASMSharedMemNode {
  18. bh_list_link l;
  19. /* Lock */
  20. korp_mutex lock;
  21. /* The module reference */
  22. WASMModuleCommon *module;
  23. /* The memory information */
  24. WASMMemoryInstanceCommon *memory_inst;
  25. /* Lock used for atomic operations */
  26. korp_mutex shared_mem_lock;
  27. /* reference count */
  28. uint32 ref_count;
  29. } WASMSharedMemNode;
  30. bool
  31. wasm_shared_memory_init();
  32. void
  33. wasm_shared_memory_destroy();
  34. void
  35. notify_stale_threads_on_exception(WASMModuleInstanceCommon *module);
  36. WASMSharedMemNode *
  37. wasm_module_get_shared_memory(WASMModuleCommon *module);
  38. int32
  39. shared_memory_inc_reference(WASMModuleCommon *module);
  40. int32
  41. shared_memory_dec_reference(WASMModuleCommon *module);
  42. WASMMemoryInstanceCommon *
  43. shared_memory_get_memory_inst(WASMSharedMemNode *node);
  44. WASMSharedMemNode *
  45. shared_memory_set_memory_inst(WASMModuleCommon *module,
  46. WASMMemoryInstanceCommon *memory);
  47. uint32
  48. wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
  49. uint64 expect, int64 timeout, bool wait64);
  50. uint32
  51. wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
  52. uint32 count);
  53. #ifdef __cplusplus
  54. }
  55. #endif
  56. #endif /* end of _WASM_SHARED_MEMORY_H */