Skip to content

Commit

Permalink
stress
Browse files Browse the repository at this point in the history
  • Loading branch information
RandomShaper committed Oct 3, 2024
1 parent 13aa42c commit 4173d11
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
9 changes: 4 additions & 5 deletions core/templates/rid_owner.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class RID_Alloc : public RID_AllocBase {
uint32_t **free_list_chunks = nullptr;

uint32_t elements_in_chunk;
std::atomic<uint32_t> max_alloc = 0;
uint32_t max_alloc = 0;
uint32_t alloc_count = 0;
uint32_t chunk_limit = 0;

Expand All @@ -90,8 +90,7 @@ class RID_Alloc : public RID_AllocBase {
mutex.lock();
}

uint32_t curr_max_alloc = max_alloc.load(std::memory_order_relaxed);
if (alloc_count == curr_max_alloc) {
if (alloc_count == max_alloc) {
//allocate a new chunk
uint32_t chunk_count = alloc_count == 0 ? 0 : (max_alloc / elements_in_chunk);
if (THREAD_SAFE && chunk_count == chunk_limit) {
Expand Down Expand Up @@ -121,7 +120,7 @@ class RID_Alloc : public RID_AllocBase {
free_list_chunks[chunk_count][i] = alloc_count + i;
}

max_alloc.store(curr_max_alloc + elements_in_chunk, std::memory_order_release);
max_alloc += elements_in_chunk;
}

uint32_t free_index = free_list_chunks[alloc_count / elements_in_chunk][alloc_count % elements_in_chunk];
Expand Down Expand Up @@ -171,7 +170,7 @@ class RID_Alloc : public RID_AllocBase {

uint64_t id = p_rid.get_id();
uint32_t idx = uint32_t(id & 0xFFFFFFFF);
if (unlikely(idx >= max_alloc.load(std::memory_order_acquire))) {
if (unlikely(idx >= max_alloc)) {
return nullptr;
}

Expand Down
2 changes: 0 additions & 2 deletions tests/core/templates/test_rid.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ TEST_CASE("[RID_Owner] Thread safety") {
tester.test();
}
}
#if 0
SUBCASE("All items in one chunk, NOT pre-allocated") {
RID_OwnerTester tester(true, false);
tester.test();
Expand All @@ -247,7 +246,6 @@ TEST_CASE("[RID_Owner] Thread safety") {
RID_OwnerTester tester(false, false);
tester.test();
}
#endif
}
} // namespace TestRID

Expand Down

0 comments on commit 4173d11

Please sign in to comment.