Commit cd33ef20 authored by gejun's avatar gejun

Replace InternalReset/DeleteStuff with ResetPods/NonPods & Save protocol-param…

Replace InternalReset/DeleteStuff with ResetPods/NonPods & Save protocol-param in thrift_method_name which is rarely used
parent f16cb5f8
...@@ -123,12 +123,12 @@ static void CreateVars() { ...@@ -123,12 +123,12 @@ static void CreateVars() {
Controller::Controller() { Controller::Controller() {
CHECK_EQ(0, pthread_once(&s_create_vars_once, CreateVars)); CHECK_EQ(0, pthread_once(&s_create_vars_once, CreateVars));
*g_ncontroller << 1; *g_ncontroller << 1;
InternalReset(true); ResetPods();
} }
Controller::~Controller() { Controller::~Controller() {
*g_ncontroller << -1; *g_ncontroller << -1;
DeleteStuff(); ResetNonPods();
} }
class IgnoreAllRead : public ProgressiveReader { class IgnoreAllRead : public ProgressiveReader {
...@@ -148,11 +148,13 @@ static void CreateIgnoreAllRead() { s_ignore_all_read = new IgnoreAllRead; } ...@@ -148,11 +148,13 @@ static void CreateIgnoreAllRead() { s_ignore_all_read = new IgnoreAllRead; }
// directly and indirectly referenced), do them in this method. Notice that // directly and indirectly referenced), do them in this method. Notice that
// you don't have to set the fields to initial state after deletion since // you don't have to set the fields to initial state after deletion since
// they'll be set uniformly after this method is called. // they'll be set uniformly after this method is called.
void Controller::DeleteStuff() { void Controller::ResetNonPods() {
if (_span) { if (_span) {
Span::Submit(_span, butil::cpuwide_time_us()); Span::Submit(_span, butil::cpuwide_time_us());
} }
_error_text.clear(); _error_text.clear();
_remote_side = butil::EndPoint();
_local_side = butil::EndPoint();
if (_session_local_data) { if (_session_local_data) {
_server->_session_local_data_pool->Return(_session_local_data); _server->_session_local_data_pool->Return(_session_local_data);
} }
...@@ -193,13 +195,12 @@ void Controller::DeleteStuff() { ...@@ -193,13 +195,12 @@ void Controller::DeleteStuff() {
_rpa.reset(NULL); _rpa.reset(NULL);
} }
delete _remote_stream_settings; delete _remote_stream_settings;
_thrift_method_name.clear();
CHECK(_unfinished_call == NULL);
} }
void Controller::InternalReset(bool in_constructor) { void Controller::ResetPods() {
if (!in_constructor) {
DeleteStuff();
CHECK(_unfinished_call == NULL);
}
// NOTE: Make the sequence of assignments same with the order that they're // NOTE: Make the sequence of assignments same with the order that they're
// defined in header. Better for cpu cache and faster for lookup. // defined in header. Better for cpu cache and faster for lookup.
_span = NULL; _span = NULL;
...@@ -208,8 +209,6 @@ void Controller::InternalReset(bool in_constructor) { ...@@ -208,8 +209,6 @@ void Controller::InternalReset(bool in_constructor) {
set_pb_bytes_to_base64(true); set_pb_bytes_to_base64(true);
#endif #endif
_error_code = 0; _error_code = 0;
_remote_side = butil::EndPoint();
_local_side = butil::EndPoint();
_session_local_data = NULL; _session_local_data = NULL;
_server = NULL; _server = NULL;
_oncancel_id = INVALID_BTHREAD_ID; _oncancel_id = INVALID_BTHREAD_ID;
...@@ -253,7 +252,6 @@ void Controller::InternalReset(bool in_constructor) { ...@@ -253,7 +252,6 @@ void Controller::InternalReset(bool in_constructor) {
_request_stream = INVALID_STREAM_ID; _request_stream = INVALID_STREAM_ID;
_response_stream = INVALID_STREAM_ID; _response_stream = INVALID_STREAM_ID;
_remote_stream_settings = NULL; _remote_stream_settings = NULL;
_thrift_method_name = "";
} }
Controller::Call::Call(Controller::Call* rhs) Controller::Call::Call(Controller::Call* rhs)
...@@ -485,7 +483,7 @@ private: ...@@ -485,7 +483,7 @@ private:
int Controller::RunOnCancel(bthread_id_t id, void* data, int error_code) { int Controller::RunOnCancel(bthread_id_t id, void* data, int error_code) {
if (error_code == 0) { if (error_code == 0) {
// Called from Controller::DeleteStuff upon Controller's Reset or // Called from Controller::ResetNonPods upon Controller's Reset or
// destruction, we just call the callback in-place. // destruction, we just call the callback in-place.
static_cast<google::protobuf::Closure*>(data)->Run(); static_cast<google::protobuf::Closure*>(data)->Run();
CHECK_EQ(0, bthread_id_unlock_and_destroy(id)); CHECK_EQ(0, bthread_id_unlock_and_destroy(id));
......
...@@ -413,7 +413,10 @@ public: ...@@ -413,7 +413,10 @@ public:
// Resets the Controller to its initial state so that it may be reused in // Resets the Controller to its initial state so that it may be reused in
// a new call. Must NOT be called while an RPC is in progress. // a new call. Must NOT be called while an RPC is in progress.
void Reset() { InternalReset(false); } void Reset() {
ResetNonPods();
ResetPods();
}
// Causes Failed() to return true on the client side. "reason" will be // Causes Failed() to return true on the client side. "reason" will be
// incorporated into the message returned by ErrorText(). // incorporated into the message returned by ErrorText().
...@@ -522,9 +525,9 @@ private: ...@@ -522,9 +525,9 @@ private:
// the container(MongoContextMessage) and all related cntl(s) are recycled. // the container(MongoContextMessage) and all related cntl(s) are recycled.
void set_mongo_session_data(MongoContext* data); void set_mongo_session_data(MongoContext* data);
// Initialize/reset all fields. // Reset POD/non-POD fields.
void InternalReset(bool in_constructor); void ResetPods();
void DeleteStuff(); void ResetNonPods();
void StartCancel(); void StartCancel();
...@@ -619,6 +622,9 @@ private: ...@@ -619,6 +622,9 @@ private:
return has_flag(FLAGS_ENABLED_CIRCUIT_BREAKER); return has_flag(FLAGS_ENABLED_CIRCUIT_BREAKER);
} }
std::string& protocol_param() { return _thrift_method_name; }
const std::string& protocol_param() const { return _thrift_method_name; }
private: private:
// NOTE: align and group fields to make Controller as compact as possible. // NOTE: align and group fields to make Controller as compact as possible.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment