Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

BUG: Add cpp atomic support #28234

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

Merged
merged 2 commits into from
Jan 27, 2025
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
15 changes: 13 additions & 2 deletions 15 numpy/_core/src/common/npy_atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@

#include "numpy/npy_common.h"

#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
#ifdef __cplusplus
extern "C++" {
#include <atomic>
}
#define _NPY_USING_STD using namespace std
#define _Atomic(tp) atomic<tp>
#define STDC_ATOMICS
#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L \
&& !defined(__STDC_NO_ATOMICS__)
// TODO: support C++ atomics as well if this header is ever needed in C++
#include <stdatomic.h>
#include <stdint.h>
#define _NPY_USING_STD
#define STDC_ATOMICS
#elif _MSC_VER
#include <intrin.h>
Expand All @@ -35,6 +42,7 @@
static inline npy_uint8
npy_atomic_load_uint8(const npy_uint8 *obj) {
#ifdef STDC_ATOMICS
_NPY_USING_STD;
return (npy_uint8)atomic_load((const _Atomic(uint8_t)*)obj);
#elif defined(MSC_ATOMICS)
#if defined(_M_X64) || defined(_M_IX86)
Expand All @@ -50,6 +58,7 @@ npy_atomic_load_uint8(const npy_uint8 *obj) {
static inline void*
npy_atomic_load_ptr(const void *obj) {
#ifdef STDC_ATOMICS
_NPY_USING_STD;
return atomic_load((const _Atomic(void *)*)obj);
#elif defined(MSC_ATOMICS)
#if SIZEOF_VOID_P == 8
Expand All @@ -73,6 +82,7 @@ npy_atomic_load_ptr(const void *obj) {
static inline void
npy_atomic_store_uint8(npy_uint8 *obj, npy_uint8 value) {
#ifdef STDC_ATOMICS
_NPY_USING_STD;
atomic_store((_Atomic(uint8_t)*)obj, value);
#elif defined(MSC_ATOMICS)
_InterlockedExchange8((volatile char *)obj, (char)value);
Expand All @@ -85,6 +95,7 @@ static inline void
npy_atomic_store_ptr(void *obj, void *value)
{
#ifdef STDC_ATOMICS
_NPY_USING_STD;
atomic_store((_Atomic(void *)*)obj, value);
#elif defined(MSC_ATOMICS)
_InterlockedExchangePointer((void * volatile *)obj, (void *)value);
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.