void task::enqueue(task_worker_pool* pool) { this->add_ref(); // released in exec_internal (even when cancelled) if (spec().type == TASK_TYPE_COMPUTE) { spec().on_task_enqueue.execute(task::get_current_task(), this); } // for delayed tasks, refering to timer service if (_delay_milliseconds != 0) { pool->add_timer(this); return; } // fast execution if (_is_null) { dassert (_node == task::get_current_node(), ""); exec_internal(); } else if (_spec->fast_execution_in_network_thread) { if (_node != task::get_current_node()) { tools::node_scoper ns(_node); exec_internal(); } else { exec_internal(); } } else if (_spec->allow_inline && !task::get_current_worker2() /*in io-thread*/ ) { dassert(_node == task::get_current_node(), ""); exec_internal(); } // normal path else { dassert(pool != nullptr, "pool %s not ready, and there are usually two cases: " "(1). thread pool not designatd in '[%s] pools'; " "(2). the caller is executed in io threads " "which is forbidden unless you explicitly set [task.%s].fast_execution_in_network_thread = true", dsn_threadpool_code_to_string(_spec->pool_code), _node->spec().config_section.c_str(), _spec->name.c_str() ); pool->enqueue(this); } }
void task_engine::get_runtime_info(const std::string& indent, const std::vector<std::string>& args, /*out*/ std::stringstream& ss) { std::string indent2 = indent + "\t"; for (auto& p : _pools) { if (p) { ss << indent << dsn_threadpool_code_to_string(p->spec().pool_code) << std::endl; p->get_runtime_info(indent2, args, ss); } } }
void task_engine::get_queue_info(/*out*/ std::stringstream& ss) { bool first_flag = 0; for (auto& p : _pools) { if (p) { if (!first_flag) first_flag = 1; else ss << ","; ss << "\t{\"pool_name\":\""<<dsn_threadpool_code_to_string(p->spec().pool_code) <<"\",\n\t\"pool_queue\":\n"; p->get_queue_info(ss); ss << "}\n"; } } }
void task::enqueue(task_worker_pool* pool) { this->add_ref(); // released in exec_internal (even when cancelled) dassert(pool != nullptr, "pool %s not ready, and there are usually two cases: " "(1). thread pool not designatd in '[%s] pools'; " "(2). the caller is executed in io threads " "which is forbidden unless you explicitly set [task.%s].allow_inline = true", dsn_threadpool_code_to_string(_spec->pool_code), _node->spec().config_section.c_str(), _spec->name.c_str() ); if (spec().type == TASK_TYPE_COMPUTE) { spec().on_task_enqueue.execute(get_current_task(), this); } // for delayed tasks, refering to timer service if (_delay_milliseconds != 0) { pool->add_timer(this); return; } // fast execution if (_is_null) { dassert (_node == task::get_current_node(), ""); exec_internal(); return; } if (_spec->allow_inline) { // inlined // warning - this may lead to deadlocks, e.g., allow_inlined // task tries to get a non-recursive lock that is already hold // by the caller task if (_node != get_current_node()) { tools::node_scoper ns(_node); exec_internal(); } else { exec_internal(); } //if (_spec->type == TASK_TYPE_COMPUTE) //{ // if (_node != get_current_node()) // { // tools::node_scoper ns(_node); // exec_internal(); // } // else // { // exec_internal(); // } // return; //} //// io tasks only inlined in io threads //if (get_current_worker2() == nullptr) //{ // dassert(_node == task::get_current_node(), ""); // exec_internal(); // return; //} } // normal path pool->enqueue(this); }