| 394 | } |
| 395 | |
| 396 | Status ThreadPool::Init() { |
| 397 | if (!pool_status_.IsUninitialized()) { |
| 398 | return Status::NotSupported("The thread pool is already initialized"); |
| 399 | } |
| 400 | pool_status_ = Status::OK(); |
| 401 | num_threads_pending_start_ = min_threads_; |
| 402 | for (int i = 0; i < min_threads_; i++) { |
| 403 | Status status = CreateThread(); |
| 404 | if (!status.ok()) { |
| 405 | Shutdown(); |
| 406 | return status; |
| 407 | } |
| 408 | } |
| 409 | if (enable_scheduler_) { |
| 410 | scheduler_ = new SchedulerThread(name_, schedule_period_ms_); |
| 411 | RETURN_NOT_OK(scheduler_->Start()); |
| 412 | } |
| 413 | return Status::OK(); |
| 414 | } |
| 415 | |
| 416 | void ThreadPool::Shutdown() { |
| 417 | { |
no test coverage detected