| 525 | } |
| 526 | |
| 527 | ThreadPool::ThreadPool() |
| 528 | : sp_state_(std::make_shared<ThreadPool::State>()), |
| 529 | state_(sp_state_.get()), |
| 530 | shutdown_on_destroy_(true) { |
| 531 | // Eternal thread pools would produce false leak reports in the vector of |
| 532 | // atfork handlers. |
| 533 | # if !(defined(_WIN32) || defined(ADDRESS_SANITIZER) || defined(ARROW_VALGRIND)) |
| 534 | state_->atfork_handler_ = std::make_shared<AtForkHandler>( |
| 535 | /*before=*/ |
| 536 | [weak_state = std::weak_ptr<ThreadPool::State>(sp_state_)]() { |
| 537 | auto state = weak_state.lock(); |
| 538 | if (state) { |
| 539 | state->BeforeFork(); |
| 540 | } |
| 541 | return state; // passed to after-forkers |
| 542 | }, |
| 543 | /*parent_after=*/ |
| 544 | [](std::any token) { |
| 545 | auto state = std::any_cast<std::shared_ptr<ThreadPool::State>>(token); |
| 546 | if (state) { |
| 547 | state->ParentAfterFork(); |
| 548 | } |
| 549 | }, |
| 550 | /*child_after=*/ |
| 551 | [](std::any token) { |
| 552 | auto state = std::any_cast<std::shared_ptr<ThreadPool::State>>(token); |
| 553 | if (state) { |
| 554 | state->ChildAfterFork(); |
| 555 | } |
| 556 | }); |
| 557 | RegisterAtFork(state_->atfork_handler_); |
| 558 | # endif |
| 559 | } |
| 560 | |
| 561 | ThreadPool::~ThreadPool() { |
| 562 | if (shutdown_on_destroy_) { |
nothing calls this directly
no test coverage detected