2023-07-21 00:27:09 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2023 Amazon Inc. All rights reserved.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _WASM_SUSPEND_FLAGS_H
|
|
|
|
#define _WASM_SUSPEND_FLAGS_H
|
|
|
|
|
2023-07-27 13:37:23 +00:00
|
|
|
#include "bh_atomic.h"
|
2023-07-21 00:27:09 +00:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Need to terminate */
|
|
|
|
#define WASM_SUSPEND_FLAG_TERMINATE 0x1
|
|
|
|
/* Need to suspend */
|
|
|
|
#define WASM_SUSPEND_FLAG_SUSPEND 0x2
|
|
|
|
/* Need to go into breakpoint */
|
|
|
|
#define WASM_SUSPEND_FLAG_BREAKPOINT 0x4
|
|
|
|
/* Return from pthread_exit */
|
|
|
|
#define WASM_SUSPEND_FLAG_EXIT 0x8
|
2023-09-20 10:11:52 +00:00
|
|
|
/* The thread might be blocking */
|
|
|
|
#define WASM_SUSPEND_FLAG_BLOCKING 0x10
|
2023-07-21 00:27:09 +00:00
|
|
|
|
|
|
|
typedef union WASMSuspendFlags {
|
2023-07-27 13:37:23 +00:00
|
|
|
bh_atomic_32_t flags;
|
2023-07-21 00:27:09 +00:00
|
|
|
uintptr_t __padding__;
|
|
|
|
} WASMSuspendFlags;
|
|
|
|
|
2023-07-27 13:37:23 +00:00
|
|
|
#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)
|
2023-07-21 00:27:09 +00:00
|
|
|
#define WASM_SUSPEND_FLAGS_FETCH_OR(s_flags, val) \
|
2023-07-27 13:37:23 +00:00
|
|
|
BH_ATOMIC_32_FETCH_OR(s_flags.flags, val)
|
2023-07-21 00:27:09 +00:00
|
|
|
#define WASM_SUSPEND_FLAGS_FETCH_AND(s_flags, val) \
|
2023-07-27 13:37:23 +00:00
|
|
|
BH_ATOMIC_32_FETCH_AND(s_flags.flags, val)
|
2023-07-21 00:27:09 +00:00
|
|
|
|
2024-01-19 01:55:01 +00:00
|
|
|
#define WASM_SUSPEND_FLAG_INHERIT_MASK (~WASM_SUSPEND_FLAG_BLOCKING)
|
|
|
|
|
2023-07-21 00:27:09 +00:00
|
|
|
#if WASM_SUSPEND_FLAGS_IS_ATOMIC != 0
|
|
|
|
#define WASM_SUSPEND_FLAGS_LOCK(lock) (void)0
|
|
|
|
#define WASM_SUSPEND_FLAGS_UNLOCK(lock) (void)0
|
|
|
|
#else /* else of WASM_SUSPEND_FLAGS_IS_ATOMIC */
|
|
|
|
#define WASM_SUSPEND_FLAGS_LOCK(lock) os_mutex_lock(&lock)
|
|
|
|
#define WASM_SUSPEND_FLAGS_UNLOCK(lock) os_mutex_unlock(&lock);
|
|
|
|
#endif /* WASM_SUSPEND_FLAGS_IS_ATOMIC */
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-07-27 13:37:23 +00:00
|
|
|
#endif /* end of _WASM_SUSPEND_FLAGS_H */
|