Download include/python3.9/internal/pycore_atomic.h from camenduru/slahmr-test: direct link, hf CLI and curl.
- Browser
- Download file 17 kB
-
https://huggingface.co/camenduru/slahmr-test/resolve/main/include/python3.9/internal/pycore_atomic.h
- Command line
-
hf download hf://camenduru/slahmr-test/include/python3.9/internal/pycore_atomic.h
-
curl -L -o pycore_atomic.h https://huggingface.co/camenduru/slahmr-test/resolve/main/include/python3.9/internal/pycore_atomic.h
17 kB
| extern "C" { | |
| /* This is modeled after the atomics interface from C1x, according to | |
| * the draft at | |
| * http://www.open-std.org/JTC1/SC22/wg14/www/docs/n1425.pdf. | |
| * Operations and types are named the same except with a _Py_ prefix | |
| * and have the same semantics. | |
| * | |
| * Beware, the implementations here are deep magic. | |
| */ | |
| typedef enum _Py_memory_order { | |
| _Py_memory_order_relaxed = memory_order_relaxed, | |
| _Py_memory_order_acquire = memory_order_acquire, | |
| _Py_memory_order_release = memory_order_release, | |
| _Py_memory_order_acq_rel = memory_order_acq_rel, | |
| _Py_memory_order_seq_cst = memory_order_seq_cst | |
| } _Py_memory_order; | |
| typedef struct _Py_atomic_address { | |
| atomic_uintptr_t _value; | |
| } _Py_atomic_address; | |
| typedef struct _Py_atomic_int { | |
| atomic_int _value; | |
| } _Py_atomic_int; | |
| /* Use builtin atomic operations in GCC >= 4.7 */ | |
| typedef enum _Py_memory_order { | |
| _Py_memory_order_relaxed = __ATOMIC_RELAXED, | |
| _Py_memory_order_acquire = __ATOMIC_ACQUIRE, | |
| _Py_memory_order_release = __ATOMIC_RELEASE, | |
| _Py_memory_order_acq_rel = __ATOMIC_ACQ_REL, | |
| _Py_memory_order_seq_cst = __ATOMIC_SEQ_CST | |
| } _Py_memory_order; | |
| typedef struct _Py_atomic_address { | |
| uintptr_t _value; | |
| } _Py_atomic_address; | |
| typedef struct _Py_atomic_int { | |
| int _value; | |
| } _Py_atomic_int; | |
| /* Only support GCC (for expression statements) and x86 (for simple | |
| * atomic semantics) and MSVC x86/x64/ARM */ | |
| typedef enum _Py_memory_order { | |
| _Py_memory_order_relaxed, | |
| _Py_memory_order_acquire, | |
| _Py_memory_order_release, | |
| _Py_memory_order_acq_rel, | |
| _Py_memory_order_seq_cst | |
| } _Py_memory_order; | |
| typedef struct _Py_atomic_address { | |
| uintptr_t _value; | |
| } _Py_atomic_address; | |
| typedef struct _Py_atomic_int { | |
| int _value; | |
| } _Py_atomic_int; | |
| static __inline__ void | |
| _Py_atomic_signal_fence(_Py_memory_order order) | |
| { | |
| if (order != _Py_memory_order_relaxed) | |
| __asm__ volatile("":::"memory"); | |
| } | |
| static __inline__ void | |
| _Py_atomic_thread_fence(_Py_memory_order order) | |
| { | |
| if (order != _Py_memory_order_relaxed) | |
| __asm__ volatile("mfence":::"memory"); | |
| } | |
| /* Tell the race checker about this operation's effects. */ | |
| static __inline__ void | |
| _Py_ANNOTATE_MEMORY_ORDER(const volatile void *address, _Py_memory_order order) | |
| { | |
| (void)address; /* shut up -Wunused-parameter */ | |
| switch(order) { | |
| case _Py_memory_order_release: | |
| case _Py_memory_order_acq_rel: | |
| case _Py_memory_order_seq_cst: | |
| _Py_ANNOTATE_HAPPENS_BEFORE(address); | |
| break; | |
| case _Py_memory_order_relaxed: | |
| case _Py_memory_order_acquire: | |
| break; | |
| } | |
| switch(order) { | |
| case _Py_memory_order_acquire: | |
| case _Py_memory_order_acq_rel: | |
| case _Py_memory_order_seq_cst: | |
| _Py_ANNOTATE_HAPPENS_AFTER(address); | |
| break; | |
| case _Py_memory_order_relaxed: | |
| case _Py_memory_order_release: | |
| break; | |
| } | |
| } | |
| /* _Interlocked* functions provide a full memory barrier and are therefore | |
| enough for acq_rel and seq_cst. If the HLE variants aren't available | |
| in hardware they will fall back to a full memory barrier as well. | |
| This might affect performance but likely only in some very specific and | |
| hard to meassure scenario. | |
| */ | |
| typedef enum _Py_memory_order { | |
| _Py_memory_order_relaxed, | |
| _Py_memory_order_acquire, | |
| _Py_memory_order_release, | |
| _Py_memory_order_acq_rel, | |
| _Py_memory_order_seq_cst | |
| } _Py_memory_order; | |
| typedef struct _Py_atomic_address { | |
| volatile uintptr_t _value; | |
| } _Py_atomic_address; | |
| typedef struct _Py_atomic_int { | |
| volatile int _value; | |
| } _Py_atomic_int; | |
| /* This has to be an intptr_t for now. | |
| gil_created() uses -1 as a sentinel value, if this returns | |
| a uintptr_t it will do an unsigned compare and crash | |
| */ | |
| inline intptr_t _Py_atomic_load_64bit_impl(volatile uintptr_t* value, int order) { | |
| __int64 old; | |
| switch (order) { | |
| case _Py_memory_order_acquire: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange64_HLEAcquire((volatile __int64*)value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_release: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange64_HLERelease((volatile __int64*)value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_relaxed: | |
| old = *value; | |
| break; | |
| default: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange64((volatile __int64*)value, old, old) != old); | |
| break; | |
| } | |
| } | |
| return old; | |
| } | |
| inline int _Py_atomic_load_32bit_impl(volatile int* value, int order) { | |
| long old; | |
| switch (order) { | |
| case _Py_memory_order_acquire: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange_HLEAcquire((volatile long*)value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_release: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange_HLERelease((volatile long*)value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_relaxed: | |
| old = *value; | |
| break; | |
| default: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange((volatile long*)value, old, old) != old); | |
| break; | |
| } | |
| } | |
| return old; | |
| } | |
| typedef enum _Py_memory_order { | |
| _Py_memory_order_relaxed, | |
| _Py_memory_order_acquire, | |
| _Py_memory_order_release, | |
| _Py_memory_order_acq_rel, | |
| _Py_memory_order_seq_cst | |
| } _Py_memory_order; | |
| typedef struct _Py_atomic_address { | |
| volatile uintptr_t _value; | |
| } _Py_atomic_address; | |
| typedef struct _Py_atomic_int { | |
| volatile int _value; | |
| } _Py_atomic_int; | |
| /* This has to be an intptr_t for now. | |
| gil_created() uses -1 as a sentinel value, if this returns | |
| a uintptr_t it will do an unsigned compare and crash | |
| */ | |
| inline intptr_t _Py_atomic_load_64bit_impl(volatile uintptr_t* value, int order) { | |
| uintptr_t old; | |
| switch (order) { | |
| case _Py_memory_order_acquire: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange64_acq(value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_release: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange64_rel(value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_relaxed: | |
| old = *value; | |
| break; | |
| default: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange64(value, old, old) != old); | |
| break; | |
| } | |
| } | |
| return old; | |
| } | |
| inline int _Py_atomic_load_32bit_impl(volatile int* value, int order) { | |
| int old; | |
| switch (order) { | |
| case _Py_memory_order_acquire: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange_acq(value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_release: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange_rel(value, old, old) != old); | |
| break; | |
| } | |
| case _Py_memory_order_relaxed: | |
| old = *value; | |
| break; | |
| default: | |
| { | |
| do { | |
| old = *value; | |
| } while(_InterlockedCompareExchange(value, old, old) != old); | |
| break; | |
| } | |
| } | |
| return old; | |
| } | |
| typedef enum _Py_memory_order { | |
| _Py_memory_order_relaxed, | |
| _Py_memory_order_acquire, | |
| _Py_memory_order_release, | |
| _Py_memory_order_acq_rel, | |
| _Py_memory_order_seq_cst | |
| } _Py_memory_order; | |
| typedef struct _Py_atomic_address { | |
| uintptr_t _value; | |
| } _Py_atomic_address; | |
| typedef struct _Py_atomic_int { | |
| int _value; | |
| } _Py_atomic_int; | |
| /* Fall back to other compilers and processors by assuming that simple | |
| volatile accesses are atomic. This is false, so people should port | |
| this. */ | |
| /* Standardized shortcuts. */ | |
| /* Python-local extensions */ | |
| } | |