File tree 1 file changed +20
-3
lines changed 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -647,6 +647,17 @@ list_contains(PyObject *aa, PyObject *el)
647
647
return 0 ;
648
648
}
649
649
650
+ static inline PyObject *
651
+ list_item_try_lock_free (PyListObject * a , Py_ssize_t i )
652
+ {
653
+ PyObject * * ob_item = FT_ATOMIC_LOAD_PTR (a -> ob_item );
654
+ PyObject * item = FT_ATOMIC_LOAD_PTR (ob_item [i ]);
655
+ if (!item || !_Py_TryIncrefCompare (& ob_item [i ], item )) {
656
+ return NULL ;
657
+ }
658
+ return item ;
659
+ }
660
+
650
661
static PyObject *
651
662
list_item (PyObject * aa , Py_ssize_t i )
652
663
{
@@ -655,15 +666,21 @@ list_item(PyObject *aa, Py_ssize_t i)
655
666
PyErr_SetObject (PyExc_IndexError , & _Py_STR (list_err ));
656
667
return NULL ;
657
668
}
658
- PyObject * item ;
669
+ #ifdef Py_GIL_DISABLED
670
+ PyObject * item = list_item_try_lock_free (a , i );
671
+ if (item != NULL ) {
672
+ goto end ;
673
+ }
674
+ #endif
659
675
Py_BEGIN_CRITICAL_SECTION (a );
676
+ item = Py_NewRef (a -> ob_item [i ]);
677
+ Py_END_CRITICAL_SECTION ();
660
678
#ifdef Py_GIL_DISABLED
679
+ end :
661
680
if (!_Py_IsOwnedByCurrentThread ((PyObject * )a ) && !_PyObject_GC_IS_SHARED (a )) {
662
681
_PyObject_GC_SET_SHARED (a );
663
682
}
664
683
#endif
665
- item = Py_NewRef (a -> ob_item [i ]);
666
- Py_END_CRITICAL_SECTION ();
667
684
return item ;
668
685
}
669
686
You can’t perform that action at this time.
0 commit comments