Skip to content

Commit 60daa68

Browse files
Update Python/qsbr.c
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
1 parent 8662728 commit 60daa68

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

Python/qsbr.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ grow_thread_array(struct _qsbr_shared *shared)
8888
// Overallocate by 63 bytes so we can align to a 64-byte boundary.
8989
// This avoids potential false sharing between the first entry and other
9090
// allocations.
91-
size_t alloc_size = (size_t)new_size * sizeof(struct _qsbr_pad) + 63;
91+
size_t alignment = 64;
92+
size_t alloc_size = (size_t)new_size * sizeof(struct _qsbr_pad) + alignment - 1;
9293
void *raw = PyMem_RawCalloc(1, alloc_size);
9394
if (raw == NULL) {
94-
return -1;
95-
}
96-
struct _qsbr_pad *array = _Py_ALIGN_UP(raw, 64);
95+
return -1;
96+
}
97+
struct _qsbr_pad *array = _Py_ALIGN_UP(raw, alignment);
9798

9899
void *old_raw = shared->array_raw;
99100
if (shared->array != NULL) {

0 commit comments

Comments
 (0)