| 385 | |
| 386 | |
| 387 | auto TransTableL::reset_memory( |
| 388 | [[maybe_unused]] const ResetReason reason) -> void |
| 389 | { |
| 390 | if (pool_ == nullptr) |
| 391 | return; |
| 392 | |
| 393 | // Temporary debug: observe reset parameters to diagnose crashes |
| 394 | #if defined(DDS_DEBUG_TT_RESET) |
| 395 | std::fprintf(stderr, |
| 396 | "[TransTableL::reset_memory] reason=%d current=%d default=%d pool=%p\n", |
| 397 | static_cast<int>(reason), |
| 398 | pages_current_, |
| 399 | pages_default_, |
| 400 | static_cast<void*>(pool_)); |
| 401 | #endif |
| 402 | |
| 403 | page_stats_.num_resets_++; |
| 404 | page_stats_.num_callocs_ += pages_current_ - page_stats_.last_current_; |
| 405 | page_stats_.last_current_ = pages_current_; |
| 406 | |
| 407 | while (pages_current_ > pages_default_) { |
| 408 | // Free the tail-most pool and unlink safely even if it was the only one. |
| 409 | Pool* cur = pool_; |
| 410 | free(cur->list_); |
| 411 | pool_ = cur->prev_; |
| 412 | free(cur); |
| 413 | if (pool_ != nullptr) { |
| 414 | pool_->next_ = nullptr; |
| 415 | } |
| 416 | |
| 417 | pages_current_--; |
| 418 | } |
| 419 | |
| 420 | page_stats_.num_frees_ += page_stats_.last_current_ - pages_current_; |
| 421 | page_stats_.last_current_ = pages_current_; |
| 422 | |
| 423 | if (pool_ != nullptr) { |
| 424 | while (pool_->prev_) |
| 425 | pool_ = pool_->prev_; |
| 426 | } |
| 427 | |
| 428 | if (pool_ != nullptr) { |
| 429 | pool_->next_block_no_ = 0; |
| 430 | next_block_ = pool_->list_; |
| 431 | } |
| 432 | else { |
| 433 | // No pool => future allocations will create a fresh pool on demand |
| 434 | next_block_ = nullptr; |
| 435 | } |
| 436 | |
| 437 | TransTableL::init_tt(); |
| 438 | |
| 439 | timestamp_ = 0; |
| 440 | |
| 441 | mem_state_ = MemState::FROM_POOL; |
| 442 | |
| 443 | } |
| 444 |
nothing calls this directly
no outgoing calls
no test coverage detected