Merge pull request #86412 from stuartcarnie/sgc/data_race

Fix data race in PagedArray
This commit is contained in:
Rémi Verschelde 2024-01-03 10:01:06 +01:00
commit a97b01c2ac
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -53,7 +53,12 @@ class PagedArrayPool {
SpinLock spin_lock;
public:
uint32_t alloc_page() {
struct PageInfo {
T *page = nullptr;
uint32_t page_id = 0;
};
PageInfo alloc_page() {
spin_lock.lock();
if (unlikely(pages_available == 0)) {
uint32_t pages_used = pages_allocated;
@ -69,13 +74,11 @@ public:
}
pages_available--;
uint32_t page = available_page_pool[pages_available];
uint32_t page_id = available_page_pool[pages_available];
T *page = page_pool[page_id];
spin_lock.unlock();
return page;
}
T *get_page(uint32_t p_page_id) {
return page_pool[p_page_id];
return PageInfo{ page, page_id };
}
void free_page(uint32_t p_page_id) {
@ -190,9 +193,9 @@ public:
_grow_page_array(); //keep out of inline
}
uint32_t page_id = page_pool->alloc_page();
page_data[page_count] = page_pool->get_page(page_id);
page_ids[page_count] = page_id;
typename PagedArrayPool<T>::PageInfo page_info = page_pool->alloc_page();
page_data[page_count] = page_info.page;
page_ids[page_count] = page_info.page_id;
}
// place the new value