Skip to content
This repository has been archived by the owner on Jun 23, 2022. It is now read-only.

feat(task): add an interface to query thread info #464

Merged
merged 18 commits into from
May 21, 2020
Merged
2 changes: 2 additions & 0 deletions include/dsn/tool-api/task.h
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ class task : public ref_counter, public extensible_object<task, 4>, public trans
static rpc_engine *get_current_rpc();
static disk_engine *get_current_disk();
static env_provider *get_current_env();
// code is in dsn/dist/replication/replication.codes.h
static std::vector<task_worker *> &get_info(int code);
Copy link
Contributor

@neverchanje neverchanje May 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// code is in dsn/dist/replication/replication.codes.h
static std::vector<task_worker *> &get_info(int code);
static const std::vector<task_worker *> &get_task_code_threads_info(task_code code);

Don't make it static member in class task, put it in global space.
The task code is not always in dsn/dist/replication/replication.codes.h, remove the comment.
The returned value must be const.


static void set_tls_dsn_context(
service_node *node, // cannot be null
Expand Down
6 changes: 6 additions & 0 deletions src/core/core/task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,12 @@ void task::enqueue(task_worker_pool *pool)
pool->enqueue(this);
}

/*static*/
std::vector<task_worker *> &task::get_info(int code)
Smityz marked this conversation as resolved.
Show resolved Hide resolved
{
return dsn::task::get_current_node2()->computation()->get_pool(code)->workers();
}

timer_task::timer_task(
task_code code, const task_handler &cb, int interval_milliseconds, int hash, service_node *node)
: task(code, hash, node), _interval_milliseconds(interval_milliseconds), _cb(cb)
Expand Down