-
Notifications
You must be signed in to change notification settings - Fork 59
valgrind: use static-allocated array to store mapping from task_code to task_spec #173
Conversation
不太赞同这种预分配512个元素的做法,几乎就是在挖坑…… |
@shengofsun 你指的是什么坑,我觉得未来也不会超过 512 task_code 了,内存占用也不大。而且其实也只是换了容器的实现方式,未来有更简单的实现或者更明确的需求都可以替换掉。 |
src/core/core/task_spec.cpp
Outdated
{ | ||
return dsn::utils::singleton_vector_store<task_spec *, nullptr>::instance().get(code); | ||
} | ||
task_spec *task_spec::get(int code) { return s_task_spec_store[code].get(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
该为:
return code < 512 ? s_task_spec_store[code].get() : nullptr;
|
||
namespace dsn { | ||
|
||
// A sequential storage maps task_code to task_spec. | ||
static std::array<std::unique_ptr<task_spec>, 512> s_task_spec_store; | ||
|
||
void task_spec::register_task_code(task_code code, | ||
dsn_task_type_t type, | ||
dsn_task_priority_t pri, | ||
dsn::threadpool_code pool) | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加上: dassert(code < 512, "code = %d", code);
src/core/core/task_spec.cpp
Outdated
{ | ||
return dsn::utils::singleton_vector_store<task_spec *, nullptr>::instance().get(code); | ||
} | ||
task_spec *task_spec::get(int code) { return code < 512 ? s_task_spec_store[code].get() : nullptr; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这么多512,定义个常量?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个建议可以采纳一下,我也这么想过
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
Valgrind warns that value pointer in
dsn::utils::singleton_vector_store<task_spec *, nullptr>
is not deleted after destruction, so we use a static allocated (512 size of capacity, enough for task_code) array ofstd::unique_ptr<task_spec>
to replace thesingleton_vector_store
implementation.valgrind report:
singleton_vector_store
is a complicated container only used for storing task_spec, we removed it also to make the code simple.This PR also suppress the warning of json_helper, see include/dsn/cpp/json_helper.h: