gh-128277: make globals variables thread safe in socket module (#128286)

This commit is contained in:
Kumar Aditya 2024-12-31 19:10:06 +05:30 committed by GitHub
parent b2ac70a62a
commit e389d6c650
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 28 additions and 36 deletions

View file

@ -1468,14 +1468,14 @@ set_inheritable(int fd, int inheritable, int raise, int *atomic_flag_works)
assert(!(atomic_flag_works != NULL && inheritable));
if (atomic_flag_works != NULL && !inheritable) {
if (*atomic_flag_works == -1) {
if (_Py_atomic_load_int_relaxed(atomic_flag_works) == -1) {
int isInheritable = get_inheritable(fd, raise);
if (isInheritable == -1)
return -1;
*atomic_flag_works = !isInheritable;
_Py_atomic_store_int_relaxed(atomic_flag_works, !isInheritable);
}
if (*atomic_flag_works)
if (_Py_atomic_load_int_relaxed(atomic_flag_works))
return 0;
}