MCPcopy Create free account
hub / github.com/apache/brpc / signal_task

Method signal_task

src/bthread/task_control.cpp:564–592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

562}
563
564void 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
594void TaskControl::print_rq_sizes(std::ostream& os) {
595 size_t ngroup = 0;

Callers 4

ready_to_runMethod · 0.80
flush_nosignal_tasksMethod · 0.80
ready_to_run_remoteMethod · 0.80

Calls 4

fmix64Function · 0.85
pthread_numeric_idFunction · 0.85
signalMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected