Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bh_atomic.h: add comments #2398

Merged
merged 2 commits into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions core/shared/utils/bh_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,38 @@
extern "C" {
#endif

/*
* Why don't we use C11 stdatomics here?
*
* Unlike C11 stdatomics,
*
* - bh_atomic_xxx_t is guaranteed to have the same size as the base type.
* Thus more friendly to our AOT conventions.
*
* - It's available for C++.
* Although C++23 will have C-compatible stdatomics.h, it isn't widely
* available yet.
*/

/*
* Note about BH_ATOMIC_32_IS_ATOMIC
*
* If BH_ATOMIC_32_IS_ATOMIC == 0, BH_ATOMIC_xxx operations defined below
* are not really atomic and require an external lock.
*
* Expected usage is:
*
* bh_atomic_32_t var = 0;
* uint32 old;
* #if BH_ATOMIC_32_IS_ATOMIC == 0
* lock(&some_lock);
* #endif
* old = BH_ATOMIC_32_FETCH_AND(var, 1);
* #if BH_ATOMIC_32_IS_ATOMIC == 0
* unlock(&some_lock);
* #endif
*/

typedef uint32 bh_atomic_32_t;

#if defined(__GNUC_PREREQ)
Expand Down