Skip to content

Commit

Permalink
Fixed pointer arithmetics in wait state initialization on reallocation.
Browse files Browse the repository at this point in the history
Fixes #72.
  • Loading branch information
Lastique committed Nov 21, 2024
1 parent b202228 commit 5e2e016
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 4 additions & 0 deletions doc/changelog.qbk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@

[section:changelog Changelog]

[heading Boost 1.87]

* Fixed initialization of atomic wait state list on memory reallocation. ([github_issue 72])

[heading Boost 1.86]

* Use [@https://man.openbsd.org/OpenBSD-6.2/futex.2 `futex(2)`] system call on OpenBSD since recent OpenBSD versions have removed support for `syscall(2)`.
Expand Down
4 changes: 2 additions & 2 deletions src/lock_pool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1252,11 +1252,11 @@ wait_state_list::header* wait_state_list::allocate_buffer(std::size_t new_capaci

const volatile void** old_a = get_atomic_pointers(old_header);
std::memcpy(a, old_a, old_header->size * sizeof(const volatile void*));
std::memset(a + old_header->size * sizeof(const volatile void*), 0, (new_capacity - old_header->size) * sizeof(const volatile void*));
std::memset(a + old_header->size, 0, (new_capacity - old_header->size) * sizeof(const volatile void*));

wait_state** old_w = get_wait_states(old_a, old_header->capacity);
std::memcpy(w, old_w, old_header->capacity * sizeof(wait_state*)); // copy spare wait state pointers
std::memset(w + old_header->capacity * sizeof(wait_state*), 0, (new_capacity - old_header->capacity) * sizeof(wait_state*));
std::memset(w + old_header->capacity, 0, (new_capacity - old_header->capacity) * sizeof(wait_state*));
}
else
{
Expand Down

0 comments on commit 5e2e016

Please sign in to comment.