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

valgrind: use static-allocated array to store mapping from task_code to task_spec #173

Merged
merged 9 commits into from
Oct 16, 2018
5 changes: 1 addition & 4 deletions include/dsn/cpp/json_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,7 @@ class json_forwarder
{
std::ostringstream os;
encode(os, t);
std::string *result = new std::string(os.str());
return dsn::blob(std::shared_ptr<char>(const_cast<char *>(result->c_str()),
[result](char *) { delete result; }),
result->length());
return blob::create_from_bytes(os.str());
}

static bool decode(const JsonObject &in, T &t)
Expand Down
1 change: 0 additions & 1 deletion include/dsn/tool-api/task_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <dsn/utility/config_helper.h>
#include <dsn/utility/enum_helper.h>
#include <dsn/utility/customizable_id.h>
#include <dsn/utility/singleton_vector_store.h>
#include <dsn/utility/join_point.h>
#include <dsn/utility/extensible_object.h>
#include <dsn/utility/exp_delay.h>
Expand Down
93 changes: 0 additions & 93 deletions include/dsn/utility/singleton_vector_store.h

This file was deleted.

20 changes: 11 additions & 9 deletions src/core/core/task_spec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,26 @@
*/

#include <dsn/tool-api/task_spec.h>
#include <dsn/utility/singleton.h>
#include <dsn/perf_counter/perf_counter.h>
#include <dsn/tool-api/command_manager.h>
#include <dsn/tool-api/threadpool_spec.h>
#include <sstream>
#include <vector>
#include <thread>
#include <dsn/utility/smart_pointers.h>

namespace dsn {

constexpr int TASK_SPEC_STORE_CAPACITY = 512;

// A sequential storage maps task_code to task_spec.
static std::array<std::unique_ptr<task_spec>, TASK_SPEC_STORE_CAPACITY> 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)
{
Copy link
Member

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);

if (!dsn::utils::singleton_vector_store<task_spec *, nullptr>::instance().contains(code)) {
task_spec *spec = new task_spec(code, code.to_string(), type, pri, pool);
dsn::utils::singleton_vector_store<task_spec *, nullptr>::instance().put(code, spec);
dassert(code < TASK_SPEC_STORE_CAPACITY, "code = %d", code);
if (!s_task_spec_store[code]) {
s_task_spec_store[code] = make_unique<task_spec>(code, code.to_string(), type, pri, pool);
auto &spec = s_task_spec_store[code];

if (type == TASK_TYPE_RPC_REQUEST) {
std::string ack_name = std::string(code.to_string()) + std::string("_ACK");
Expand Down Expand Up @@ -114,7 +116,7 @@ void task_spec::register_storage_task_code(task_code code,

task_spec *task_spec::get(int code)
{
return dsn::utils::singleton_vector_store<task_spec *, nullptr>::instance().get(code);
return code < TASK_SPEC_STORE_CAPACITY ? s_task_spec_store[code].get() : nullptr;
}

task_spec::task_spec(int code,
Expand Down