-
-
Notifications
You must be signed in to change notification settings - Fork 11.1k
MAINT: use an atomic load/store and a mutex to initialize the argparse and runtime import caches #26780
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
MAINT: use an atomic load/store and a mutex to initialize the argparse and runtime import caches #26780
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e55b25c
TST: add a test to check if the argparse cache is thread safe
ngoldbaum 6386423
MNT: lock initializing the argparse cache
ngoldbaum 9a22d84
MNT: convert runtime imports to use single-initialization
ngoldbaum 6ea18a4
MAINT: re-add libatomic link test to meson.build
ngoldbaum 3c620cb
MAINT: add support for gcc builtin atomics
ngoldbaum 2e2fa1d
MAINT: rework to use double-checked locking and avoid new struct
ngoldbaum b6af99a
BUG: fix windows build
ngoldbaum dabfe59
MAINT: respond to review comments
ngoldbaum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
MNT: lock initializing the argparse cache
- Loading branch information
commit 6386423f6a88b35e0ed0c06effe8cd8c3dec82fb
There are no files selected for viewing
8000
View file
Open in desktop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Provides wrappers around C11 standard library atomics and MSVC intrinsics | ||
* to provide basic atomic load and store functionality. This is based on | ||
* code in CPython's pyatomic.h, pyatomic_std.h, and pyatomic_msc.h | ||
ngoldbaum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
*/ | ||
|
||
#ifndef NUMPY_CORE_SRC_COMMON_NPY_ATOMIC_H_ | ||
#define NUMPY_CORE_SRC_COMMON_NPY_ATOMIC_H_ | ||
|
||
#include "numpy/npy_common.h" | ||
|
||
#if __STDC_VERSION__ >= 201112L && !defined(__STDC_NO_ATOMICS__) | ||
// TODO: support C++ atomics as well if this header is ever needed in C++ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code to do this is in the CPython header this is cribbed from. It would be dead code if I included it. |
||
#include <stdatomic.h> | ||
#include <stdint.h> | ||
#define STDC_ATOMICS | ||
#elif _MSC_VER | ||
#include <intrin.h> | ||
#define MSC_ATOMICS | ||
#else | ||
#error "no support for missing C11 atomics except with MSVC" | ||
#endif | ||
|
||
|
||
static inline npy_uint8 npy_atomic_load_uint8(const npy_uint8 *obj) { | ||
#ifdef STDC_ATOMICS | ||
return (npy_uint8)atomic_load((const _Atomic(uint8_t)*)obj); | ||
#elif defined(MSC_ATOMICS) | ||
#if defined(_M_X64) || defined(_M_IX86) | ||
return *(volatile npy_uint8 *)obj; | ||
#elif defined(_M_ARM64) | ||
return (npy_uint8)__ldar8((unsigned __int8 volatile *)obj); | ||
#else | ||
#error "Unsupported MSVC build configuration, neither x86 or ARM" | ||
#endif | ||
#endif | ||
} | ||
|
||
#undef MSC_ATOMICS | ||
#undef STDC_ATOMICS | ||
|
||
#endif // NUMPY_CORE_SRC_COMMON_NPY_NPY_ATOMIC_H_ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.