wasm_shared_memory.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. #include "../interpreter/wasm_runtime.h"
  9. #include "wasm_runtime_common.h"
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif
  13. extern korp_mutex g_shared_memory_lock;
  14. bool
  15. wasm_shared_memory_init(void);
  16. void
  17. wasm_shared_memory_destroy(void);
  18. uint16
  19. shared_memory_inc_reference(WASMMemoryInstance *memory);
  20. uint16
  21. shared_memory_dec_reference(WASMMemoryInstance *memory);
  22. #define shared_memory_is_shared(memory) memory->is_shared_memory
  23. #define shared_memory_lock(memory) \
  24. do { \
  25. /* \
  26. * Note: exception logic is currently abusing this lock. \
  27. * cf. \
  28. * https://github.com/bytecodealliance/wasm-micro-runtime/issues/2407 \
  29. */ \
  30. bh_assert(memory != NULL); \
  31. if (memory->is_shared_memory) \
  32. os_mutex_lock(&g_shared_memory_lock); \
  33. } while (0)
  34. #define shared_memory_unlock(memory) \
  35. do { \
  36. if (memory->is_shared_memory) \
  37. os_mutex_unlock(&g_shared_memory_lock); \
  38. } while (0)
  39. uint32
  40. wasm_runtime_atomic_wait(WASMModuleInstanceCommon *module, void *address,
  41. uint64 expect, int64 timeout, bool wait64);
  42. uint32
  43. wasm_runtime_atomic_notify(WASMModuleInstanceCommon *module, void *address,
  44. uint32 count);
  45. #ifdef __cplusplus
  46. }
  47. #endif
  48. #endif /* end of _WASM_SHARED_MEMORY_H */