mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-02-06 06:55:07 +00:00
Move generic parts of wasm_suspend_flags.h to bh_atomic.h (#2393)
This commit is contained in:
parent
6110ea39fd
commit
228417ab8c
|
@ -6,7 +6,7 @@
|
|||
#ifndef _WASM_SUSPEND_FLAGS_H
|
||||
#define _WASM_SUSPEND_FLAGS_H
|
||||
|
||||
#include "bh_platform.h"
|
||||
#include "bh_atomic.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
@ -22,42 +22,16 @@ extern "C" {
|
|||
#define WASM_SUSPEND_FLAG_EXIT 0x8
|
||||
|
||||
typedef union WASMSuspendFlags {
|
||||
uint32 flags;
|
||||
bh_atomic_32_t flags;
|
||||
uintptr_t __padding__;
|
||||
} WASMSuspendFlags;
|
||||
|
||||
#if defined(__GNUC_PREREQ)
|
||||
#if __GNUC_PREREQ(4, 7)
|
||||
#define CLANG_GCC_HAS_ATOMIC_BUILTIN
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0)
|
||||
#define CLANG_GCC_HAS_ATOMIC_BUILTIN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CLANG_GCC_HAS_ATOMIC_BUILTIN)
|
||||
#define WASM_SUSPEND_FLAGS_IS_ATOMIC 1
|
||||
#define WASM_SUSPEND_FLAGS_GET(s_flags) \
|
||||
__atomic_load_n(&s_flags.flags, __ATOMIC_SEQ_CST)
|
||||
#define WASM_SUSPEND_FLAGS_IS_ATOMIC BH_ATOMIC_32_IS_ATOMIC
|
||||
#define WASM_SUSPEND_FLAGS_GET(s_flags) BH_ATOMIC_32_LOAD(s_flags.flags)
|
||||
#define WASM_SUSPEND_FLAGS_FETCH_OR(s_flags, val) \
|
||||
__atomic_fetch_or(&s_flags.flags, val, __ATOMIC_SEQ_CST)
|
||||
BH_ATOMIC_32_FETCH_OR(s_flags.flags, val)
|
||||
#define WASM_SUSPEND_FLAGS_FETCH_AND(s_flags, val) \
|
||||
__atomic_fetch_and(&s_flags.flags, val, __ATOMIC_SEQ_CST)
|
||||
#else /* else of defined(CLANG_GCC_HAS_ATOMIC_BUILTIN) */
|
||||
#define WASM_SUSPEND_FLAGS_GET(s_flags) (s_flags.flags)
|
||||
#define WASM_SUSPEND_FLAGS_FETCH_OR(s_flags, val) (s_flags.flags |= val)
|
||||
#define WASM_SUSPEND_FLAGS_FETCH_AND(s_flags, val) (s_flags.flags &= val)
|
||||
|
||||
/* The flag can be defined by the user if the platform
|
||||
supports atomic access to uint32 aligned memory. */
|
||||
#ifdef WASM_UINT32_IS_ATOMIC
|
||||
#define WASM_SUSPEND_FLAGS_IS_ATOMIC 1
|
||||
#else /* else of WASM_UINT32_IS_ATOMIC */
|
||||
#define WASM_SUSPEND_FLAGS_IS_ATOMIC 0
|
||||
#endif /* WASM_UINT32_IS_ATOMIC */
|
||||
|
||||
#endif
|
||||
BH_ATOMIC_32_FETCH_AND(s_flags.flags, val)
|
||||
|
||||
#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0
|
||||
#define WASM_SUSPEND_FLAGS_LOCK(lock) (void)0
|
||||
|
@ -71,4 +45,4 @@ typedef union WASMSuspendFlags {
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _WASM_SUSPEND_FLAGS_H */
|
||||
#endif /* end of _WASM_SUSPEND_FLAGS_H */
|
||||
|
|
53
core/shared/utils/bh_atomic.h
Normal file
53
core/shared/utils/bh_atomic.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright (C) 2023 Amazon Inc. All rights reserved.
|
||||
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
||||
*/
|
||||
|
||||
#ifndef _BH_ATOMIC_H
|
||||
#define _BH_ATOMIC_H
|
||||
|
||||
#include "gnuc.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef uint32 bh_atomic_32_t;
|
||||
|
||||
#if defined(__GNUC_PREREQ)
|
||||
#if __GNUC_PREREQ(4, 7)
|
||||
#define CLANG_GCC_HAS_ATOMIC_BUILTIN
|
||||
#endif
|
||||
#elif defined(__clang__)
|
||||
#if __clang_major__ > 3 || (__clang_major__ == 3 && __clang_minor__ >= 0)
|
||||
#define CLANG_GCC_HAS_ATOMIC_BUILTIN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(CLANG_GCC_HAS_ATOMIC_BUILTIN)
|
||||
#define BH_ATOMIC_32_IS_ATOMIC 1
|
||||
#define BH_ATOMIC_32_LOAD(v) __atomic_load_n(&(v), __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_32_FETCH_OR(v, val) \
|
||||
__atomic_fetch_or(&(v), (val), __ATOMIC_SEQ_CST)
|
||||
#define BH_ATOMIC_32_FETCH_AND(v, val) \
|
||||
__atomic_fetch_and(&(v), (val), __ATOMIC_SEQ_CST)
|
||||
#else /* else of defined(CLANG_GCC_HAS_ATOMIC_BUILTIN) */
|
||||
#define BH_ATOMIC_32_LOAD(v) (v)
|
||||
#define BH_ATOMIC_32_FETCH_OR(v, val) ((v) |= (val))
|
||||
#define BH_ATOMIC_32_FETCH_AND(v, val) ((v) &= (val))
|
||||
|
||||
/* The flag can be defined by the user if the platform
|
||||
supports atomic access to uint32 aligned memory. */
|
||||
#ifdef WASM_UINT32_IS_ATOMIC
|
||||
#define BH_ATOMIC_32_IS_ATOMIC 1
|
||||
#else /* else of WASM_UINT32_IS_ATOMIC */
|
||||
#define BH_ATOMIC_32_IS_ATOMIC 0
|
||||
#endif /* WASM_UINT32_IS_ATOMIC */
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* end of _BH_ATOMIC_H */
|
|
@ -16,7 +16,6 @@
|
|||
#include "bh_log.h"
|
||||
#include "bh_queue.h"
|
||||
#include "bh_vector.h"
|
||||
#include "gnuc.h"
|
||||
#include "runtime_timer.h"
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user