File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed
Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,18 @@ typedef struct {
197197static PyDateTime_CAPI * PyDateTimeAPI = NULL ;
198198
199199#define PyDateTime_IMPORT \
200- PyDateTimeAPI = (PyDateTime_CAPI *)PyCapsule_Import(PyDateTime_CAPSULE_NAME, 0)
200+ do { \
201+ void *val = _Py_atomic_load_ptr(&PyDateTimeAPI); \
202+ if (val == NULL) { \
203+ PyDateTime_CAPI *capi = (PyDateTime_CAPI *)PyCapsule_Import( \
204+ PyDateTime_CAPSULE_NAME, 0); \
205+ if (capi != NULL) { \
206+ /* it is okay if the compare exchange fails as in that case
207+ another thread would have initialized it */ \
208+ _Py_atomic_compare_exchange_ptr (& PyDateTimeAPI , & val , (void * )capi ); \
209+ } \
210+ } \
211+ } while (0 )
201212
202213/* Macro for access to the UTC singleton */
203214#define PyDateTime_TimeZone_UTC PyDateTimeAPI->TimeZone_UTC
You can’t perform that action at this time.
0 commit comments