gh-116908: Only write to `_pending_calls.calls_to_do` with atomic operations (#117044)

These writes to `pending->calls_to_do` need to be atomic, because other threads
can read (atomically) from `calls_to_do` without holding `pending->mutex`.
This commit is contained in:
Brett Simmers 2024-03-20 08:18:26 -07:00 committed by GitHub
parent fc45998007
commit 9221ef2d8c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -671,7 +671,7 @@ _push_pending_call(struct _pending_calls *pending,
pending->calls[i].flags = flags; pending->calls[i].flags = flags;
pending->last = j; pending->last = j;
assert(pending->calls_to_do < NPENDINGCALLS); assert(pending->calls_to_do < NPENDINGCALLS);
pending->calls_to_do++; _Py_atomic_add_int32(&pending->calls_to_do, 1);
return 0; return 0;
} }
@ -701,7 +701,7 @@ _pop_pending_call(struct _pending_calls *pending,
pending->calls[i] = (struct _pending_call){0}; pending->calls[i] = (struct _pending_call){0};
pending->first = (i + 1) % NPENDINGCALLS; pending->first = (i + 1) % NPENDINGCALLS;
assert(pending->calls_to_do > 0); assert(pending->calls_to_do > 0);
pending->calls_to_do--; _Py_atomic_add_int32(&pending->calls_to_do, -1);
} }
} }