| 615 | } |
| 616 | |
| 617 | void server_models::unload_all() { |
| 618 | std::vector<std::thread> to_join; |
| 619 | { |
| 620 | std::lock_guard<std::mutex> lk(mutex); |
| 621 | for (auto & [name, inst] : mapping) { |
| 622 | if (inst.meta.is_active()) { |
| 623 | SRV_INF("unloading model instance name=%s\n", name.c_str()); |
| 624 | stopping_models.insert(name); |
| 625 | cv_stop.notify_all(); |
| 626 | // status change will be handled by the managing thread |
| 627 | } |
| 628 | // moving the thread to join list to avoid deadlock |
| 629 | to_join.push_back(std::move(inst.th)); |
| 630 | } |
| 631 | } |
| 632 | for (auto & th : to_join) { |
| 633 | if (th.joinable()) { |
| 634 | th.join(); |
| 635 | } |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | void server_models::update_status(const std::string & name, server_model_status status, int exit_code) { |
| 640 | std::unique_lock<std::mutex> lk(mutex); |