| 562 | } |
| 563 | |
| 564 | void TaskControl::signal_task(int num_task, bthread_tag_t tag) { |
| 565 | if (num_task <= 0) { |
| 566 | return; |
| 567 | } |
| 568 | // TODO(gejun): Current algorithm does not guarantee enough threads will |
| 569 | // be created to match caller's requests. But in another side, there's also |
| 570 | // many useless signalings according to current impl. Capping the concurrency |
| 571 | // is a good balance between performance and timeliness of scheduling. |
| 572 | if (num_task > 2) { |
| 573 | num_task = 2; |
| 574 | } |
| 575 | auto& pl = tag_pl(tag); |
| 576 | size_t start_index = butil::fmix64(pthread_numeric_id()) % _pl_num_of_each_tag; |
| 577 | for (size_t i = 0; i < _pl_num_of_each_tag && num_task > 0; ++i) { |
| 578 | num_task -= pl[start_index].signal(1); |
| 579 | if (++start_index >= _pl_num_of_each_tag) { |
| 580 | start_index = 0; |
| 581 | } |
| 582 | } |
| 583 | if (num_task > 0 && |
| 584 | FLAGS_bthread_min_concurrency > 0 && // test min_concurrency for performance |
| 585 | _concurrency.load(butil::memory_order_relaxed) < FLAGS_bthread_concurrency) { |
| 586 | // TODO: Reduce this lock |
| 587 | BAIDU_SCOPED_LOCK(g_task_control_mutex); |
| 588 | if (_concurrency.load(butil::memory_order_acquire) < FLAGS_bthread_concurrency) { |
| 589 | add_workers(1, tag); |
| 590 | } |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | void TaskControl::print_rq_sizes(std::ostream& os) { |
| 595 | size_t ngroup = 0; |
no test coverage detected