MCPcopy Create free account
hub / github.com/apache/incubator-pegasus / register_task_code

Method register_task_code

src/runtime/task/task_spec.cpp:55–106  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

53static std::array<std::unique_ptr<task_spec>, TASK_SPEC_STORE_CAPACITY> s_task_spec_store;
54
55void task_spec::register_task_code(task_code code,
56 dsn_task_type_t type,
57 dsn_task_priority_t pri,
58 dsn::threadpool_code pool)
59{
60 CHECK_GE(code, 0);
61 CHECK_LT(code, TASK_SPEC_STORE_CAPACITY);
62 if (!s_task_spec_store[code]) {
63 s_task_spec_store[code] =
64 std::make_unique<task_spec>(code, code.to_string(), type, pri, pool);
65 auto &spec = s_task_spec_store[code];
66
67 if (type == TASK_TYPE_RPC_REQUEST) {
68 std::string ack_name = std::string(code.to_string()) + std::string("_ACK");
69 // for a rpc request, we firstly register it's ack code to invalid threadpool,
70 // then the response code's definition will reassign a proper valid threadpool code.
71 // please refer to the DEFINE_TASK_CODE_RPC/DEFINE_STORAGE_RPC_CODE in task_code.h
72 // for more details.
73 dsn::task_code ack_code(
74 ack_name.c_str(), TASK_TYPE_RPC_RESPONSE, pri, THREAD_POOL_INVALID);
75 spec->rpc_paired_code = ack_code;
76 task_spec::get(ack_code.code())->rpc_paired_code = code;
77 }
78 } else {
79 auto spec = task_spec::get(code);
80 CHECK_EQ_MSG(
81 spec->type,
82 type,
83 "task code {} registerd for {}, which does not match with previously registered {}",
84 code,
85 enum_to_string(type),
86 enum_to_string(spec->type));
87
88 if (spec->priority != pri) {
89 LOG_WARNING("overwrite priority for task {} from {} to {}",
90 code,
91 enum_to_string(spec->priority),
92 enum_to_string(pri));
93 spec->priority = pri;
94 }
95
96 if (spec->pool_code != pool) {
97 if (spec->pool_code != THREAD_POOL_INVALID) {
98 LOG_WARNING("overwrite default thread pool for task {} from {} to {}",
99 code,
100 spec->pool_code,
101 pool);
102 }
103 spec->pool_code = pool;
104 }
105 }
106}
107
108void task_spec::register_storage_task_code(task_code code,
109 dsn_task_type_t type,

Callers

nothing calls this directly

Calls 3

enum_to_stringFunction · 0.85
to_stringMethod · 0.45
codeMethod · 0.45

Tested by

no test coverage detected